パイプ記号で区切られたファイル
マイファイル.txt
Hello|how|are|you|hope|you|are|doing|fine
Lilly|jasmine|rose|sunflower|nightfire|flowers
3より大きい列を削除したいです。結果セットが欲しい
Hello|how|are
Lilly|jasmine|rose
Unix シェルスクリプトで Unix コマンドを使用します。
ベストアンサー1
OFS
および(出力)フィールド区切り文字を使用してFS
最初の3列のみを印刷します。
$ awk 'BEGIN{OFS=FS="|"}{print $1,$2,$3}' file.txt
Hello|how|are
Lilly|jasmine|rose
sed を使用して最初の 2 つだけを|[everything that's not |]
維持します。
~$ sed 's/\(\(|[^|]*\)\{2\}\).*/\1/' file.txt
Hello|how|are
Lilly|jasmine|rose