The UNIX and Linux Forums  


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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace 3 fields with null in the file vukkusila Shell Programming and Scripting 1 09-12-2007 02:10 AM
How can find Null value in If condition koti_rama Shell Programming and Scripting 2 07-17-2007 06:20 AM
Find fields with no spaces in value alfredo123 UNIX for Dummies Questions & Answers 10 04-18-2007 07:14 PM
Find files which contain a null character Bab00shka UNIX for Dummies Questions & Answers 5 12-16-2005 10:41 AM
mv /dev/null file raj8 UNIX for Dummies Questions & Answers 3 07-17-2003 05:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-22-2006
rahulrathod rahulrathod is offline
Registered User
  
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 158
Find null fields in file

Hi All,

I have some csv files out of which i want to find records which have empty values in either the 14th or 16th fields.

The following is a sample.

$cut -d',' -f14,16 SPS* | head -5
VOIP_ORIG_INFO,VOIP_DEST_INFO
sip:445600709315@sip.com,sip:999@sip.com
sip:445600709315@sip.com,tel:999
sip:445600702897@sip.com,sip:08007317929@sip.com
sip:445600702897@sip.com,sip:08007317929@sip.com

Please let me know, what would be the filter criteria to find records and filename where these fields are empty.

Thanks,
Ashish.
  #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

  #3 (permalink)  
Old 06-23-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try...
Code:
awk -F, '!$14||!$16{printf "Filename:%s Line:%s Data:%s,%s\n", FILENAME, NR, $14, $16}' SPS*

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0