The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


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


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
What's wrong with this line: if ${TEST:?} ; then echo empty; fi meili100 UNIX for Dummies Questions & Answers 2 02-23-2008 07:45 AM
checking for empty string in tcsh pagod Shell Programming and Scripting 3 12-07-2007 01:22 AM
checking size of the first line in a log file kiran1112 Shell Programming and Scripting 19 03-22-2007 10:46 AM
empty line YoYo Shell Programming and Scripting 4 09-21-2005 08:14 PM
printing an empty line in a file (perl) kfad Shell Programming and Scripting 3 05-07-2005 12:10 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Checking the Empty line in csv file

Hi all,

I have one CSV file(MasterFile.csv) consists of two columns.

"./incoming/ABC.CSV","./incoming/ABC_CONTROL.txt"
"./incoming/PQR.CSV","./incoming/PQR_CONTROL.txt"

"./incoming/123.CSV","./incoming/123_CONTROL.txt"

I have written a script to read the MasterFile.csv.Here i want to check the Empty line entry and try to ignore during the script execution...

My script code snippet is follow



writeToLog "=====New Logs for data file validation====="
writeToLog "==========================================="

validateScript="./validateFile.sh"
masterFile="./MasterFile.csv"

if [ ! -f $masterFile -o ! -r $masterFile ];
then
#exit for now, it will check again when the next cron job runs
writeToLog "In Script $0: file $masterFile not found/readable"
exit 0
fi

if [ ! -f $validateScript -o ! -r $validateScript ];
then
#exit for now, it will check again when the next cron job runs
writeToLog "In Script $0: script $validateScript not found/readable"
exit 0
fi

writeToLog "In Script $0: Going to validate all data files listed in the master file - $masterFile"
count=0
while [ 1 ]
do
#execute the following block from the 2nd line onwards, which means skip the header row of the csv file
read entryLine || break
writeToLog "In Script $0: entryLine=$entryLine"
if [ $count -gt 0 ];
then
#index of the delimiter that separates the data file and control file names
index=`echo $entryLine | awk '{ print index($1,",") }'`
writeToLog "In Script $0: index of delimiter = $index"
#need to take the substring before the comma
index=`expr $index - 1`
#echo $entryLine | awk '{ print substr($1, 0, '$index') }'
dataFile=`echo $entryLine | awk '{ print substr($1, 0, '$index') }'`
writeToLog "In Script $0: current data file = $dataFile"
index=`expr $index + 2`
controlFile=`echo $entryLine | awk '{ print substr($1, '$index') }'`
writeToLog "In Script $0: current control file = $controlFile"
#invoke script - $validateScript
sh $validateScript $dataFile $controlFile
fi
count=`expr $count + 1`
#echo "count = $count"
done < $masterFile
writeToLog "In Script $0: Finished validation of all data files listed in the master file - $masterFile"

exit 0

PFA contains the required files..

Cheers
Soll
Attached Files
File Type: zip Script.zip (3.6 KB, 1 views)
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: Jul 2006
Posts: 187
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
just to ignore empty lines

Code:
grep -v "^$" <filename>
Reply With Quote
  #3 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Hi aju_kup

Could you guide me how to append the grep -v "^$" <filename> in the existing code.

I'm new to Unix Scripting.It will be very helpful to complete this task

Cheers

Soll
Reply With Quote
  #4 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: Jul 2006
Posts: 187
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
writeToLog "In Script $0: Going to validate all data files listed in the master file - $masterFile"
count=0
while [ 1 ]
do

Quote:
echo $entryline | grep "^$" > /dev/null

if [ $? -eq "0" ]
then
continue
fi
#execute the following block from the 2nd line onwards, which means skip the header row of the csv file
read entryLine || break
writeToLog "In Script $0: entryLine=$entryLine"
if [ $count -gt 0 ];
then
Reply With Quote
  #5 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Thanks a Lot Mr.aju_kup for you immediate reply...
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB 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 -7. The time now is 10:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102