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

Script to find blank records in a file except for few columns

$
0
0
I have a file with the following format:
Code:

X|High|2|GIC|DM||XHM|||6 Months 
X|Moderate|2|GIC|DM||XHM|||6 Months 
X|High|2|GCM|DM||XSF|||6 Months 
X|Med|2|GCM|DM||XSF|||6

Here there are ten columns but I need to print rows having blank records in any of the rows (except for 6th,8th and 9th column which will remain blank by default in each row(s)). Records are separated by "| " delimiter

I tried this :
Code:

awk -F'|' '{
for (i=1; i<=NF; ++i)
{
if($i == 6 || $i == 8 || $i == 9)
{
$i++;continue;
}
elseif ($i ~ /^[[:space:]]*$/)
{print NR, $0; next}}' file.txt

But it says that "awk" is unable to parse the command. Can someone help in modifying it?

Viewing all articles
Browse latest Browse all 16232

Trending Articles