Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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/4/unix/3.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
Shell 字符串作为“粘贴”命令的分隔符_Shell_Unix_Paste - Fatal编程技术网

Shell 字符串作为“粘贴”命令的分隔符

Shell 字符串作为“粘贴”命令的分隔符,shell,unix,paste,Shell,Unix,Paste,我有三个文件,内容如下: one.txt a b c 1 2 3 Some text with all kinds of characters (but no single quote). More text, also with "all kinds of characters" (and no single quote either). Same as before. two.txt a b c 1 2 3 Some text with all kinds of character

我有三个文件,内容如下:

one.txt

a
b
c
1
2
3
Some text with all kinds of characters (but no single quote).
More text, also with "all kinds of characters" (and no single quote either).
Same as before.
two.txt

a
b
c
1
2
3
Some text with all kinds of characters (but no single quote).
More text, also with "all kinds of characters" (and no single quote either).
Same as before.
three.txt

a
b
c
1
2
3
Some text with all kinds of characters (but no single quote).
More text, also with "all kinds of characters" (and no single quote either).
Same as before.
我想将这三个文件合并为:

'a', '1', 'Some text with all kinds of characters (but no single quote).'
'b', '2', 'More text, also with "all kinds of characters" (and no single quote either).'
'c', '3', 'Same as before.'

也就是说,我希望字符串
,“
(即单引号、逗号、空格、单引号)作为三个文件之间的分隔符,并且–如果您想尝试高级答案–a
a作为每一行的开头和结尾。

使用
粘贴
awk

paste one.txt two.txt three.txt | awk -F '\t' -v SQ="'" -v OFS=', ' '{
     for (i=1; i<=NF; i++) printf "%s%s%s%s", SQ, $i, SQ, (i<NF)?OFS:ORS}'
'a', '1', 'Some text with all kinds of characters (but not single quote).'
'b', '2', 'More text, also with "all kinds of characters" (and no single quote either).'
'c', '3', 'Same as before.'
paste one.txt two.txt three.txt | awk-F'\t'-v SQ=“”“-v OFS=”,”{

对于(i=1;iYes,它确实是
paste one.txt two.txt three.txt
。我刚才的文件名是
1 2 3
太棒了!谢谢:-)