2014-03-26 31 views
0

我有一個文件1,它包含: aaaaaaa bbbbbbb cccccccLinux外殼上的多個文件

文件2: ddddddd eeeeeee fffffff

文件N: ggggggg hhhhhhh iiiiiii

如何使用正則表達式外殼Linux的預加thisistheresult,並有這樣的結果文件: thisistheresultaaaaaaa,bbbbbbb,ccccccc thisistheresultddddddd,eeeeeee,fffffff thisistheresultggggggg,hhhhhhh,iiiiiii 感謝您的任何幫助!

回答

3

使用pastesed

paste -s file* -d',' | sed 's/^/thisistheresult/' 
+0

我得到這個 ' thisistheresultaaaaaaa
,BBBBBBB
,CCCCCCC
' 這是不對的。 – YOU

+0

我的意思是它不在oneline。can you fix it,thanks – YOU

+0

嗯,我得到的輸出正是你想要的。我試圖理解你看到的行爲。 – perreal

1

我假定文件名以file開頭。 下面的代碼應該在bash中工作。

for i in file*; do echo -n 'thisistheresult'; paste -sd, $i; done 
1

嘗試。

> for f in file* 
> do 
> echo thisistheresult$(tr '\n' ',' < $f) 
> done 
1
find -name 'file*' | xargs -iF tcsh -c "tr '\n', ',' < F | sed 's/^/thisistheresult/' && echo" > result.file 
1

試試這個:

paste -s * | tr '\t' ',' | awk 'BEGIN { OFS = ""}{print "thisistheresult",$0}' 

輸出:

thisistheresultaaaaaaa,bbbbbbb,ccccccc 
thisistheresultddddddd,eeeeeee,fffffff 

,如果你想 「thisistheresult」 和 「AAAAAAA」 之間的空間剛剛擺脫BEGIN命令:

paste -s * | tr '\t' ',' | awk '{print "thisistheresult",$0}' 

輸出:

thisistheresult aaaaaaa,bbbbbbb,ccccccc 
thisistheresult ddddddd,eeeeeee,fffffff