案例一:将文件testfile的第一列和testfile2的第二列取出来,输出到另一个文件中。
testfile和testfile2分别如下:
[root@172-0-10-222 shell-test]# cat testfile
ll 201907001 80 97 70
kk 201907002 90 97 90
hh 201908003 67 60 77
jj 201908004 59 57 58
aa 201909005 67 82 63
[root@172-0-10-222 shell-test]# cat testfile2
hello nice to meet you
world what do you do
welcome to hangzhou
方法一:分别使用awk取出testfile的第一列和testfile2的第二列并分别重定向到文件a和b,然后使用paste将文件a和b的内容放在一起然后重定向到文件c。
[root@172-0-10-222 shell-test]# awk '{print $1}' testfile > a
[root@172-0-10-222 shell-test]# awk '{print $2}' testfile2 > b
[root@172-0-10-222 shell-test]# paste a b
ll nice
kk what
hh to
jj
aa
[root@172-0-10-222 shell-test]# paste a b | sed 's/\t/ /'
ll nice
kk what
hh to
jj
aa
或者使用:paste a b | tr "\t" " "
[root@172-0-10-222 shell-test]# paste a b | sed 's/\t/