Linux 在单个命令中使用变量在grep多个结果上追加字符串
文件名包含空格,例如Linux 在单个命令中使用变量在grep多个结果上追加字符串,linux,bash,perl,awk,grep,Linux,Bash,Perl,Awk,Grep,文件名包含空格,例如像这样的示例.txt,我想在该字符串的前缀和后缀上附加“。例如“像这样的示例.txt” 此外,我还想在grep结果的每一行上追加数字 例如,此命令将返回几行: ls -a | grep "filename" 例如: example filename a.txt example filename b.txt example filename c.txt example filename d.txt $ ls -la | awk '/filename/{printf "%s
像这样的示例.txt
,我想在该字符串的前缀和后缀上附加“
。例如“像这样的示例.txt”
此外,我还想在grep结果的每一行上追加数字
例如,此命令将返回几行:
ls -a | grep "filename"
例如:
example filename a.txt
example filename b.txt
example filename c.txt
example filename d.txt
$ ls -la | awk '/filename/{printf "%s %s%s%s\n",++i,q,$0,q}' q='"'
1 "example filename a.txt"
2 "example filename b.txt"
3 "example filename c.txt"
4 "example filename d.txt"
如何使用单个命令在每个返回行上附加多个字符串?以便获得以下输出:
1 "example filename a.txt"
2 "example filename b.txt"
3 "example filename c.txt"
4 "example filename d.txt"
如果需要一个命令,则需要使用类似于
awk
、perl
或python
的命令:
例如:
example filename a.txt
example filename b.txt
example filename c.txt
example filename d.txt
$ ls -la | awk '/filename/{printf "%s %s%s%s\n",++i,q,$0,q}' q='"'
1 "example filename a.txt"
2 "example filename b.txt"
3 "example filename c.txt"
4 "example filename d.txt"
在您的预期输出中,这些数字应该来自哪里?