簡體   English   中英

Linux Shell上的多個文件

[英]Linux shell on multiple files

我有一個文件1,其中包含: aaaaaaa bbbbbbb ccccccc

文件2: ddddddd eeeeeee fffffff

文件n: ggggggg hhhhhhh iiiiiii

如何使用regex shell linux預先添加thisistheresult並生成如下結果文件: thisistheresultaaaaaaa,bbbbbbb,ccccccc thisistheresultddddddd,eeeeeee,fffffff thisistheresultggggggg,hhhhhhh,iiiiiii感謝您的幫助!

使用pastesed

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

我假設文件名以file開頭。 以下代碼應在bash中工作。

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

嘗試這個。

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

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM