我有一个这样的文件:
method AAA one (1,111):
some_text_1
method BBB two (2,
222):
tuesday
method CCC three (3,
333):
sunny_day
method DDD four (4,
444_a,
444_b):
last_week
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样:
method AAA one (1,111):
some_text_1
method BBB two (2,222):
tuesday
method CCC three (3,333):
sunny_day
method DDD four (4,444_a,444_b):
last_week
Run Code Online (Sandbox Code Playgroud)
我有这个 sed 命令几乎可以做到:
sed -i '/method/,/):/ p; :a; N; $!b a; s/\n\s\{1,\}//g' file.txt
Run Code Online (Sandbox Code Playgroud)
它给出了这个输出:
method AAA one (1,111):
method AAA one (1,111):some_text_1
method BBB two (2,222):tuesday
method CCC three (3,333):sunny_day
method DDD four (4,444_a,444_b): …
Run Code Online (Sandbox Code Playgroud)