テキストファイルの内容は次のとおりです。
chair
table
pen
desk
var
それでは、以下のように変更して変数に保存したいと思います。
(「椅子」、「椅子」)、(「テーブル」、「テーブル」)、(「ペン」、「ペン」)、(「テーブル」、「テーブル」)
可能ですか?
編集する Jofelの答えは、次のエラーを提供します。
$ sed ':a;N;$!ba;s/\n/,/g;s/\w*/(''&'',''&'')/g' -i csclm.txt
sed: The label :a;N;$!ba;s/\n/,/g;s/\w*/(&,&)/g is greater than eight characters.
私は以下を使用しています:
$ uname -a
HP-UX rcihp145 B.11.23 U 9000/800 3683851961 unlimited-user license
ベストアンサー1
それを使用する1つの方法sed
:
コンテンツscript.sed:
## Change line.
s/.*/('&','&')/
## Append it to hold space.
H
## In end of file substitute newlines with commas and print.
$ {
g
s/^\n//
s/\n/,/g
p
}
注文する:
sed -nf script.sed infile
出力:
('chair','chair'),('table','table'),('pen','pen'),('desk','desk')