2

file1.txtUnixにテキスト ファイルがあります。別のファイルを作成したいのですfile2.txtが、この形式の行のすべてのグループを変更します (多肢選択式試験から取得)。

a. [first choice]
b. [second choice]
c. [third choice]

[first choice] [second choice] [third choice]

どうすればそれができますか?

編集:例は

What is the value of three plus five?
a. six
b. seven
c. eight

This line is not so relevant.
blah blah

What is the capital of England?
a. London
b. Birmingham
c. New York

に変換する必要があります

What is the value of three plus five?
six seven eight

This line is not so relevant.
blah blah

What is the capital of England?
London Birmingham New York    
4

1 に答える 1

3

このワンライナーはあなたのために働くはずです:

 awk '{if($0~/^[a-z]\. /){gsub(/^[a-z]\. /,"");printf "%s ",$0;s=1;next;}else{if(s)print "";print $0;s=0}}' file1

テスト

kent$  cat exam
What is the value of three plus five?
a. six
b. seven
c. eight

This line is not so relevant.
blah blah

What is the capital of England?
a. London
b. Birmingham
c. New York

kent$  awk '{if($0~/^[a-z]\. /){gsub(/^[a-z]\. /,"");printf "%s ",$0;s=1;next;}else{if(s)print "";print $0;s=0}}' exam
What is the value of three plus five?
six seven eight 

This line is not so relevant.
blah blah

What is the capital of England?
London Birmingham New York  
于 2012-12-01T20:36:42.233 に答える