The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 06-22-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
How do you know that a field is empty? Would there be just two commas following each other? Something like this?
Code:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17...
1,2,3,4,5,6,7,8,9,10,11,12,13,,15,16,17...
1,2,3,4,5,6,7,8,9,10,11,12,13,,15,,17...
Note that the fourteenth field is empty in the second and the third line, while the sixteenth field is empty in the third line.
If so, then you can just use the command that you've used.
Code:
bash-3.00$ cat test
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
1,2,3,4,5,6,7,8,9,10,11,12,13,,15,16,17
1,2,3,4,5,6,7,8,9,10,11,12,13,,15,,17
bash-3.00$ cat test.sh
#!/usr/bin/ksh
oldIFS=$IFS
IFS=$IFS,
export IFS
cut -d',' -f14,16 test|while read fourteen sixteen; do
        echo fourteen: $fourteen sixteen: $sixteen
        [[ -z "$fourteen" ]] && echo fourteenth field is blank
        [[ -z "$sixteen" ]] && echo sixteenth field is blank
done