在下面的文本中,我想跳过第一行,并将$放在从Part1开始的行的前面。我写了我的剧本,但它不起作用。你能帮帮我吗
Input
------
Intro
Part1 Yellow
Part2 Red
Part3 Green
Part1 Yellow
Desired output:
--------------
$Part1 Yellow
Part2 Red
Part3 Green
$Part1 Yellow
Code:
awk 'NR>1 {$0~/Part1/($0="$ "$0)}1' myfile
Error:
awk: Syntax error Context is:
>>> NR>1 {$0~/Part1/( <<<
2条答案
按热度按时间dojqjjoe1#
使用所示示例,请尝试以下操作
awk
。简单的解释是,它跳过了第一行(FNR>1
)条件,并且检查一行是否以Part1
开始,然后在当前行的值前面添加$
。然后提到1
将打印编辑/未编辑的行。guz6ccqo2#
如果你想跳过第一行并且不打印它,我会在你的代码中做这样的修改:
或者更简洁: