I have a file that has let's say, 5 columns(obtained by redirecting the results of a Sybase select query). Each column is separated by a tab. I need to filter out the columns that have all NULLs. Any column among the five can be null.
For example, if the columns in the file look like the below:
1000 NULL NULL 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
7 NULL 1000 2 NULL
The output must be(after removing columns 2 and 5), preferably in the same file:
1000 NULL 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
7 1000 2
I reached:
for i in {1..5}
do
echo $i
dlr="$"$i
str="{print $dlr}"
echo $str
awk '$str' <input_file> | while read value
do
echo $value
if [ "$value" == "NULL" ]
then
echo "inside"
cut $i
fi
done
done
value right now, shows all the rows!!! Also, I am not sure how to cut off the column. I am a shell script beginner and unable to proceed further.
Can you please advise how to do this?