Skip to main content
deleted 126 characters in body
Source Link
Swarnagowri
  • 525
  • 5
  • 10
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 
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 
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 
edited tags
Link
jesse_b
  • 41.6k
  • 14
  • 108
  • 163
Source Link
Swarnagowri
  • 525
  • 5
  • 10

How to not display a column that has all NULL values in a file

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?