2015-04-05 126 views
1

我有兩個文件。 一個文件的名稱帶有空格,另一個文件的空格已經被mighty和強大的tr命令替換爲underbar。逐行交織兩個文本文件

cat /tmp/crap2 
Effective awk Programming, 3rd Edition.pdf 
Fashion Photography by Edward Steichen in the 1920s and 1930s (15).jpg 
Fashion Photography by Edward Steichen in the 1920s and 1930s (19).jpg 
Fashion Photography by Edward Steichen in the 1920s and 1930s (30).jpg 
Fashion Photography by Edward Steichen in the 1920s and 1930s (4).jpg 
sed & awk, 2nd Edition.pdf 


cat /tmp/crap 
Effective_awk_Programming,_3rd_Edition.pdf 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(15).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(19).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(30).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(4).jpg 
sed_&_awk,_2nd_Edition.pdf 

我要讓這樣的輸出供顯示該文件makinng顯示一個帶下劃線和其他與沒有底線:

Effective_awk_Programming,_3rd_Edition.pdf 
Effective awk Programming, 3rd Edition.pdf 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(15).jpg 
Fashion Photography by Edward Steichen in the 1920s and 1930s (15).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(19).jpg 
Fashion Photography by Edward Steichen in the 1920s and 1930s (19).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(30).jpg 
Fashion Photography by Edward Steichen in the 1920s and 1930s (30).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(4).jpg 
Fashion Photography by Edward Steichen in the 1920s and 1930s (4).jpg 
sed_&_awk,_2nd_Edition.pdf 
sed & awk, 2nd Edition.pdf 

但是當我使用bash命令用while循環和嵌套的for循環,我得到很大的爛攤子輸出:

$ while read line ; do for i in $(cat /tmp/crap); do echo $i ; done ; echo $line ; done < /tmp/crap2 


Effective_awk_Programming,_3rd_Edition.pdf 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(15).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(19).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(30).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(4).jpg 
sed_&amp;_awk,_2nd_Edition.pdf 
Fashion Photography by Edward Steichen in the 1920s and 1930s (30).jpg 
cat /tmp/crap) 
cat /tmp/crap 
Effective_awk_Programming,_3rd_Edition.pdf 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(15).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(19).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(30).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(4).jpg 
sed_&amp;_awk,_2nd_Edition.pdf 
Fashion Photography by Edward Steichen in the 1920s and 1930s (4).jpg 
cat /tmp/crap) 
cat /tmp/crap 
Effective_awk_Programming,_3rd_Edition.pdf 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(15).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(19).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(30).jpg 
Fashion_Photography_by_Edward_Steichen_in_the_1920s_and_1930s_(4).jpg 
sed_&amp;_awk,_2nd_Edition.pdf 
sed &amp; awk, 2nd Edition.pdf 

我已經試過其他的腳本與現在我做什麼改變IFS,然後讓不同的貓文件是

paste /tmp/crap /tmp/crap2 

兩種文件,並使用vi來進行編輯

+0

我不是一個合適的機器上,但現在,當你試着去'貓文件1文件2,會發生什麼|排序-m'? – 2015-04-05 05:13:07

+0

這不是你要求的,但我想你可能會喜歡'vimdiff/tmp/crap/tmp/crap2' – pawel7318 2015-04-05 09:48:57

回答

1

使用2文件描述符:

while read -u3 c1 && read -u4 c2; do 
    echo "$c1" 
    echo "$c2" 
done 3<crap 4<crap2 
+0

you tha man glenn – capser 2015-04-05 23:37:11

2

我相信paste-d,--delimiter選項。所以只是做

paste -d '\n' /tmp/crap /tmp/crap2 

假設cygwin的paste類似的coreutils paste或BSD paste