Checking the Empty line in csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking the Empty line in csv file
# 1  
Old 05-15-2008
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
# 2  
Old 05-15-2008
just to ignore empty lines

Code:
grep -v "^$" <filename>

# 3  
Old 05-15-2008
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  
Old 05-15-2008
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  
Old 05-15-2008
Thanks a Lot Mr.aju_kup for you immediate reply...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking data in csv file after headers

I had a requirement to check if data exists after headers (typically row 2 & so on) in csv file. please help how we can check through shellscript in linux. Thank you !! (1 Reply)
Discussion started by: chandu123
1 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. Linux

Add empty columns at the end of a CSV file

I have a .CSV file (lets say named as file.csv) with numeric and string values. The string might contain commas hence they are enclosed in double quotes as in the below format. column1,column2,column3,column4,column5,column6,column7 12,455,"string, with, quotes, and with, commas, in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

4. Programming

Checking not empty string

I have a string s Are the following equivalent? if ( ! s.empty() ) { } if ( s ) { } (1 Reply)
Discussion started by: kristinu
1 Replies

5. Shell Programming and Scripting

Checking the CSV File Columns

Hi All, i have a CSV file like below, col1 col2 col3 col4 col5 col6 col7 a1 a2 a3 a4 a5 a6 a7 b1 b2 b3 b4 b5 b6 b7 c1 c2 c3 c4 c5 c6 c7 d1 d2 d3 d4 d5 d6 d7 Col1,col2.. are the column names and... (1 Reply)
Discussion started by: dileep_d10
1 Replies

6. Shell Programming and Scripting

checking csv files with empty fields..!

Hi! I need to learn that how a shell script can transverse a csv file n check if any field is empty or not. means its contains two comma or space b/w commas i.e., "" or " ". can anyone help me out how I can do that.... (10 Replies)
Discussion started by: sukhdip
10 Replies

7. Shell Programming and Scripting

Adding New empty line in a file

Hi, I am new to Sed /awk commands. using that i want to add new empty line after every line in a file by leaving first three lines. So, can any one help me out how to achieve this. Example: --------- Input Filename: file1.txt Input Data: --------Report-------- Date:20-10-03... (4 Replies)
Discussion started by: G.K.K
4 Replies

8. Shell Programming and Scripting

howto add line as a first line into a non empty file

Hi Trying to do like this : echo "$variable1\n $(cat file.txt)" but it only adds one time. When I run this cmd again with different variable it only replaces line of variable1. How to add constantly line into first line in file ? (3 Replies)
Discussion started by: presul
3 Replies

9. Shell Programming and Scripting

Add Empty columns at the end of csv file

Hi, Can you please tell me how to add empty columns at the end csv file? Currently there are 6 columns in the csv file. I want to add 35 empty columns at the end of this csv file. Thanks, Tushar (17 Replies)
Discussion started by: Tushar Bendale
17 Replies

10. Web Development

Checking if a folder is empty or not using PHP

Hi, I am sharing this tip with you all.The codes given below will explain /** * Checking a folder is empty or not. * @param string $folderName * $folderName should be folder name or path * @return TRUE/FALSE (If any file or folder found/Empty folder) */ function... (1 Reply)
Discussion started by: elizas
1 Replies
Login or Register to Ask a Question