Skip to main content
added 9 characters in body
Source Link
oliv
  • 2.6k
  • 11
  • 15

Provided your input file is well tab separated, you can use this GNU awk script:

awk 'BEGIN{RS="[\t\n]"} !NF{$1="NA"} {printf "%s%s", $0, RT}' file

The record separator RS is set to the tab or newline in order to get the number of fields in NF.

If NF is empty, meaning there are not word between 2 tabs, the string NA is added.

The script prints the resulting record with the record terminator RT (a \t or a \n).

Provided your input file is well tab separated, you can use this GNU awk script:

awk 'BEGIN{RS="[\t\n]"} !NF{$1="NA"} {printf $0 RT}' file

The record separator RS is set to the tab or newline in order to get the number of fields in NF.

If NF is empty, meaning there are not word between 2 tabs, the string NA is added.

The script prints the resulting record with the record terminator RT (a \t or a \n).

Provided your input file is well tab separated, you can use this GNU awk script:

awk 'BEGIN{RS="[\t\n]"} !NF{$1="NA"} {printf "%s%s", $0, RT}' file

The record separator RS is set to the tab or newline in order to get the number of fields in NF.

If NF is empty, meaning there are not word between 2 tabs, the string NA is added.

The script prints the resulting record with the record terminator RT (a \t or a \n).

Source Link
oliv
  • 2.6k
  • 11
  • 15

Provided your input file is well tab separated, you can use this GNU awk script:

awk 'BEGIN{RS="[\t\n]"} !NF{$1="NA"} {printf $0 RT}' file

The record separator RS is set to the tab or newline in order to get the number of fields in NF.

If NF is empty, meaning there are not word between 2 tabs, the string NA is added.

The script prints the resulting record with the record terminator RT (a \t or a \n).