如何 trim 每第 n 行?

How to trim every nth line?

我想删掉第 4 行每行的前 9 个字符。我可以使用 cut -c 9,但我不知道如何仅每 4 行 select,而不会丢失剩余的行。

输入:

@V300059044L3C001R0010004402
AAGTAGATATCATGGAGCCG
+
FFFGFGGFGFGFFGFFGFFGGGGGFFFGG
@V300059044L3C001R0010009240
AAAGGGAGGGAGAATAATGG
+
GFFGFEGFGFGEFDFGGEFFGGEDEGEGF

输出:

@V300059044L3C001R0010004402
AAGTAGATATCATGGAGCCG
+
FGFFGFFGFFGGGGGFFFGG
@V300059044L3C001R0010009240
AAAGGGAGGGAGAATAATGG
+
FGEFDFGGEFFGGEDEGEGF

您能否尝试在 GNU awk.

中使用显示的示例进行跟踪、编写和测试
awk 'FNR%4==0{print substr([=10=],10);next} 1' Input_file

或按照@tripleee 的建议(在评论中)尝试:

awk '!(FNR%4) { [=11=] = substr([=11=], 10) }1' Input_file

解释:为以上添加详细解释。

awk '                   ##Starting awk program from here.
FNR%4==0{               ##Checking condition if this line number is fully divided by 4(every 4th line).
  print substr([=12=],10)   ##Printing line from 10th character here.
  next                  ##next will skip all further statements from here.
}
1                       ##1 will print current Line.
' Input_file            ##Mentioning Input_file name here.

GNU sed 可以选择每 4 行 4~4,例如:

sed -E '4~4s/.{9}//'