Sponsored Content
Top Forums Shell Programming and Scripting Checking the Empty line in csv file Post 302195471 by sollins on Thursday 15th of May 2008 07:18:18 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
DBATBL(1)						      General Commands Manual							 DBATBL(1)

NAME
dbatbl - Manage on-disk reference tables for DB-ALLe SYNOPSIS
dbatbl [command] [options] [args...] DESCRIPTION
This tool allows to index and query the tables that are needed for normal functioning of DB-ALLe. dbatbl always requires a non-switch argument, that indicates what is the operation that should be performed: help Print a help summary. help manpage Print this manpage. cat tableid [tableid [...]] Output all the contents of a WMO B table.. grep string Output all the contents of the local B table whose description contains the given string.. expand table-entry [table-entry [...]] Describe a WMO B table entry or expand a WMO D table entry in its components.. expandcode varcode [varcode [...]] Expand the value of a packed variable code. index [options] filename index-id Index the contents of a table file. describe [options] what [values] Invoke the formatter to describe the given values. Supported so far are: "level ltype l1 l2", "trange pind p1 p2". OPTIONS
dbatbl follows the usual GNU command line syntax, with long options starting with two dashes (`-'). Option for command cat -?, --help print an help message -c, --csv output variables in CSV format Option for command grep -?, --help print an help message -c, --csv output variables in CSV format Option for command expand -?, --help print an help message Option for command expandcode -?, --help print an help message Option for command index -?, --help print an help message -t type, --type=type format of the table to index ('b', 'd', 'conv') Option for command describe -?, --help print an help message AUTHOR
dbatbl has been written by Enrico Zini <enrico@enricozini.com> for ARPA Emilia Romagna, Servizio Idrometeorologico. may 16, 2012 DBATBL(1)
All times are GMT -4. The time now is 05:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy