|
藍森林 http://www.lslnet.com 2006年6月26日 11:18
請教關於文件內容用shell排序的問題
我有一個文本文件(UNIX如下:
86705008428001D 1000
86705008428001C 2000
86705008428001D 3000
86705008428001D 2500
86705008428001C 1500
86705008428001C 5000
86705008428001C 8000
如何用UNIX SHELL 把文件改為:
86705008428001D 1000 86705008428001C 2000
86705008428001D 3000 86705008428001C 1500
86705008428001D 2500 86705008428001C 5000
----------------------- 86705008428001C 8000
按頭一列最後一位字母排兩列 |
請教關於文件內容用shell排序的問題
最後一行難搞....
若不擔心那行的話:
grep D file > file.1
grep C file > file.2
past file.1 file.2 |
請教關於文件內容用shell排序的問題
[code]mkdir ttmmpp
awk '{a=substr($1,15);print >"ttmmpp/"a}' yourfile
paste ttmmpp/* >yourfile.result
rm -rf ttmmpp[/code] |
請教關於文件內容用shell排序的問題
[code]cat file|awk '{if($1~/C/)print >"a";else print >"b"}'|paste a b>newfile;rm a b[/code] |
請教關於文件內容用shell排序的問題
| 請教關於文件內容用shell排序的問題
-->
是啊,最後一行沒有對齊,缺少兩個TAB位 |
請教關於文件內容用shell排序的問題
看我的環境,可能與你的不同 |
請教關於文件內容用shell排序的問題
[code]paste <(grep D 2;print "\t\t") <(grep C 2)[/code]
用"----------"替換有點困難 |
請教關於文件內容用shell排序的問題
| 請教關於文件內容用shell排序的問題
-->
那再加一個判斷呀,兩個文件哪個行少,少幾行在末尾加上同行---------------不就行了?呵呵。
我的想法是這樣的。 |
請教關於文件內容用shell排序的問題
try:
[code]grep D file > file.1
grep C file > file.2
paste -d : file.1 file.2 | awk -F: '{printf("%22s\t%s\n",$1,$2)}'[/code] |
| |