单行 Linux/bash 打印复杂语句

-1 bash

我有一个包含两列数据的文件,让我们说:

kevin n1

edwin n2

mevin n3
Run Code Online (Sandbox Code Playgroud)

我想用这样的东西生成一个声明。

--This is kevin and his 'roll number' is n1

--This is edwin and his 'roll number' is n2

--This is mewin and his 'roll number' is n3
Run Code Online (Sandbox Code Playgroud)

现在,我无法使用awk. 它不喜欢语句中间的破折号“--”或单引号 (')。

我希望输出按照我上面显示的方式输出?

oli*_*liv 5

使用 awk:

awk 'NF{print "--This is " $1 " and his \047roll number\047 is " $2 }' file
Run Code Online (Sandbox Code Playgroud)

\047是单引号的八进制代码'

另一种选择是定义一个包含单引号字符的变量:

awk -v sq="'" 'NF{print "--This is " $1 " and his "sq"roll number"sq" is " $2 }' file
Run Code Online (Sandbox Code Playgroud)