Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Can ksh read records with blank fields

$
0
0
I have a tab delimited file with some fields potentially containing no data. In ksh 'read' though treats multiple tabs as a single delimiter. Is there any way to change that behavior so I could have blank data too? I.e. When encountering 2 tabs it would take it as a null field? Or do I have to use awk?
Code:

# where <TAB> would be a real tab:
while IFS="<TAB>" read a b c d; do echo $c; done < file.txt

vs.
Code:

awk -F"\t" '{print $3}' file.txt
The shell version will output the wrong field if the 1st or 2nd record is blank.

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images