Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 在单个命令中使用变量在grep多个结果上追加字符串_Linux_Bash_Perl_Awk_Grep - Fatal编程技术网

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"

在您的预期输出中,这些数字应该来自哪里?