当前位置: 技术问答>linux和unix
请问:如何用SH脚本实现从一个文件中取出指定的行?
来源: 互联网 发布时间:2016-04-10
本文导语: 文件1: 239526 121.229.53.235 2008-08-22 11:19:54 303226 122.159.17.142 2008-08-22 16:58:45 ...... 文件2: 116.21.145.143 239526,http://xxxx.com/cilpage/042.htm,20080822 221.210.29.137 1615383,http://xxxx.com/time/sg2007/news/client_news01.htm,20080822 .... 要从...
文件1:
239526 121.229.53.235 2008-08-22 11:19:54
303226 122.159.17.142 2008-08-22 16:58:45
......
文件2:
116.21.145.143 239526,http://xxxx.com/cilpage/042.htm,20080822
221.210.29.137 1615383,http://xxxx.com/time/sg2007/news/client_news01.htm,20080822
....
要从文件2中取出满足条件:文件2中的第二个字段在文件1中第一个字段中存在的行,如239526
最后形成文件3:
116.21.145.143 239526,http://xxxx.com/cilpage/042.htm,20080822
......
239526 121.229.53.235 2008-08-22 11:19:54
303226 122.159.17.142 2008-08-22 16:58:45
......
文件2:
116.21.145.143 239526,http://xxxx.com/cilpage/042.htm,20080822
221.210.29.137 1615383,http://xxxx.com/time/sg2007/news/client_news01.htm,20080822
....
要从文件2中取出满足条件:文件2中的第二个字段在文件1中第一个字段中存在的行,如239526
最后形成文件3:
116.21.145.143 239526,http://xxxx.com/cilpage/042.htm,20080822
......
|
sed 's/,/ /g' file2 |join file1 - -1 1 -2 2 -o 2.1,2.2,2.3,2.4|sed 's/ /,/g'|sed 's/,/ /'>file3