我想在列表文件上刪除三列與Perl。用製表符分隔的文件刪除Perl列
輸入文件:
A B C D
預期/新文件:
A B C
我在其他問題了如何刪除只有一列,答案之中:
perl.exe -na -e "print qq{$F[3]\n}" < input
如何我可以重寫這個刪除三列嗎?
感謝
我想在列表文件上刪除三列與Perl。用製表符分隔的文件刪除Perl列
輸入文件:
A B C D
預期/新文件:
A B C
我在其他問題了如何刪除只有一列,答案之中:
perl.exe -na -e "print qq{$F[3]\n}" < input
如何我可以重寫這個刪除三列嗎?
感謝
爲你做這項工作:在AWK-模式
perl.exe -na -e "print qq{@F[0..2]\n}" <input> newfile
使用Perl:
或空格分隔:
$ perl -F'\t' -lane 'print qq{@F[0..2]}' input
a b c
a b c
a b c
或打印前三列,tab-s eparated在AWK
$ awk 'BEGIN{OFS="\t"}{print $1, $2, $3}' input
a b c
a b c
a b c
perl -lane "pop @F; print qq(@F)" input
這裏的另一個選項(Perl的v5.14 +):
perl -lne "print s/.+\K\s+\S$//r" inFile
你瞭解Perl的了什麼呢?這不是要求免費解決方案或從基礎知識教程的地方。 – Borodin
只需Google'用perl標籤分隔文件刪除列'。它快得多... – fugu