Remove empty columns by awk

Vonton

I have a input file, which is tab delimited, but I want to remove all empty columns. Empty columns : $13=$14=$15=$84=$85=$86=$87=$88=$89=$91=$94

INPUT: tsv file with more than 90 columns

a b   d e   g...  
a b   d e   g...

OUTPUT: tsv file without empty columns

a b d e g....
a b d e g...

Thank you

Ed Morton

This might be what you want:

$ printf 'a\tb\tc\td\te\n'
a       b       c       d       e

$ printf 'a\tb\tc\td\te\n' | awk 'BEGIN{FS=OFS="\t"} {$2=$4=""} 1'
a               c               e

$ printf 'a\tb\tc\td\te\n' | awk 'BEGIN{FS=OFS="\t"} {$2=$4=RS; gsub("(^|"FS")"RS,"")} 1'
a       c       e

Note that the above doesn't remove all empty columns as some potential solutions might do, it only removes exactly the column numbers you want removed:

$ printf 'a\tb\t\td\te\n'
a       b               d       e

$ printf 'a\tb\t\td\te\n' | awk 'BEGIN{FS=OFS="\t"} {$2=$4=RS; gsub("(^|"FS")"RS,"")} 1'
a               e

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

jQuery empty()とremove()

分類Dev

Merge columns with the same value with awk

分類Dev

Subtotal using awk for multiple columns

分類Dev

awk search then transpose rows to columns

分類Dev

Converting an empty row into a columns in pandas

分類Dev

Angular Table and filtering empty columns

分類Dev

Remove empty objects from an object

分類Dev

How to remove empty column with heading?

分類Dev

.Bat to remove columns or remove text in a csv file

分類Dev

Merge rows by duplicate columns in awk/unix with condition

分類Dev

Matching Five Columns in two Files using Awk

分類Dev

Remove null list-columns

分類Dev

Remove rows based on columns values

分類Dev

How to dynamically remove crosstab columns

分類Dev

shell awk script to remove duplicate lines

分類Dev

sed/awk remove newline on two pattern matches

分類Dev

Remove last character from string captured with awk

分類Dev

How to remove a part of a column using awk

分類Dev

awk: Perform arithmetic on subset of columns and print all columns with modified values

分類Dev

SQL count empty cells in unknown number of columns

分類Dev

Append columns to empty table - Q/KDB+

分類Dev

Retain empty lists when unnesting columns in pandas

分類Dev

how to remove "empty" space between subplots?

分類Dev

How to remove empty elements after class?(jQuery)

分類Dev

Remove or reduce empty space between subplots

分類Dev

Javascript/lodash how to remove empty arrays

分類Dev

Remove empty rows in data-table angular

分類Dev

Remove Tuple if it Contains any Empty String Elements

分類Dev

Remove empty line before a pattern using sed

Related 関連記事

ホットタグ

アーカイブ