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
在UNIX中,读取两个文件的每一行,并将带有特殊字符的文件写入另一个文件_Unix - Fatal编程技术网

在UNIX中,读取两个文件的每一行,并将带有特殊字符的文件写入另一个文件

在UNIX中,读取两个文件的每一行,并将带有特殊字符的文件写入另一个文件,unix,Unix,我有两个文件 abc.txt abc def ghi 123.txt 123 456 789 我希望将此输出写入另一个文件: abc -> 123 def -> 456 ghi -> 789 使用sed修复您的解决方案: paste -d '-' abc.txt 123.txt -> abc123.txt | sed 's/-/->/' 当'-'可以是abc.txt中的字符时,请选择另一个唯一的字符 或者使用awk: awk 'NR==FNR {

我有两个文件

abc.txt

abc

def

ghi
123.txt

123

456

789
我希望将此输出写入另一个文件:

abc -> 123

def -> 456

ghi -> 789

使用
sed
修复您的解决方案:

paste -d '-' abc.txt 123.txt -> abc123.txt | sed 's/-/->/'
当'-'可以是abc.txt中的字符时,请选择另一个唯一的字符

或者使用
awk

awk 'NR==FNR {a[NR]=$1;next} {print $1 " -> " a[FNR] }' 123.txt abc.txt

如果您有
lam
,则:

lam abc.txt -s "->" 123.txt
我会的