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



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
What's wrong with this line: if ${TEST:?} ; then echo empty; fi meili100 UNIX for Dummies Questions & Answers 2 02-23-2008 11:45 AM
checking for empty string in tcsh pagod Shell Programming and Scripting 3 12-07-2007 05:22 AM
checking size of the first line in a log file kiran1112 Shell Programming and Scripting 19 03-22-2007 02:46 PM
empty line YoYo Shell Programming and Scripting 4 09-22-2005 12:14 AM
printing an empty line in a file (perl) kfad Shell Programming and Scripting 3 05-07-2005 04:10 AM

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 05-15-2008
sollins sollins is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
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, 8 views)
  #2 (permalink)  
Old 05-15-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
just to ignore empty lines

Code:
grep -v "^$" <filename>
  #3 (permalink)  
Old 05-15-2008
sollins sollins is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
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
  #4 (permalink)  
Old 05-15-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
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
  #5 (permalink)  
Old 05-15-2008
sollins sollins is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
Thanks a Lot Mr.aju_kup for you immediate reply...
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 05:26 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