LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-13-2011, 11:48 PM   #1
sukhdip
Member
 
Registered: Sep 2011
Posts: 54

Rep: Reputation: Disabled
comparing csv files


Hi!
I need to write a script which will read a property file, property file will be containing count of the csv files, and in a folder(same folder) there will be respective csv files.
eg,Property file
data1=100
data2=50
data3=45
data4=40
and in a directory corresponding csv files will be there.

I need to make a script that can first read property file and search for the keyword like data1 csv files in folder and match the count, if they are equal proceed proceed further if not send an error mail.Plz help me out with this
Thanks a lot..
 
Old 12-13-2011, 11:57 PM   #2
coolsg5636
Member
 
Registered: Sep 2011
Location: Pune,India
Distribution: RHEL ,CentOS, Fedora
Posts: 100

Rep: Reputation: 25
Hello,

Everyone here would like to help you but only when you have tried to write this script on your own and you are stuck at some point.

Have you tried to write this script?

If yes then please paste the code.
 
Old 12-14-2011, 12:13 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,492

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Your title is quite misleading as there is no comparison between csv files but rather you want to know if the count
of files equals the assigned variable amount (correct?).

As per previous post, please show what attempts you have made to solve the problem and where you are stuck so we may assist?
 
Old 12-21-2011, 04:36 AM   #4
sukhdip
Member
 
Registered: Sep 2011
Posts: 54

Original Poster
Rep: Reputation: Disabled
Hi!

spelling out my requirements correctly:
There is one prop file which is like a constraint file. which contains keys to tell which are mandatory columns in a csv file.
Say MAN_COL=1,2,5,6

Now a script need to check the prop file first then to pick the value about mandatory columns.
Then it will go to csv file. Read it line by line. Check the mandatory columns if they have some value in it means they are not empty or null.
if they are null script will send a mail to some address.
otherwise it will return 0.

As m new n learning from ground i tried commands here m posting those one.
These are just commands need to combine them to make a working script for my requirement.
help needed..
help me out.
Here is the code tried by me:
Code:
#!/bin/bash
#while loop to read line by line
N=0
While read LINE ; do
N=$((N+1))
echo “Line $N = $LINE
done

# cut command to extract columns
cut –f 1,3,4 –d ‘|’ Jewson.csv

#if else clause to check the columns if they contain something or empty
if ($1==[a-zA-Z][0-9] && $2==[a-zA-Z][0-9] && $3==$1==[a-zA-Z][0-9])
then
return 0
else
#send mail to admin {code for sendmail server}
fi
Thanks a lot....
 
Old 12-21-2011, 04:38 AM   #5
sukhdip
Member
 
Registered: Sep 2011
Posts: 54

Original Poster
Rep: Reputation: Disabled
i need to know how i will send output of one command to next one in above scenario. How i will i make it a working script....
n do lemme know Am I a little bit on right track or am just on a diff track in diff world.....
 
Old 12-21-2011, 07:51 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,492

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
I would probably suggest using awk as it is best suited to reading files and separating them by columns as required.

A good reference is http://www.gnu.org/software/gawk/man...ode/index.html

To get you started:

1. Look at the field separator as the default is whitespace and you want a comma

2. Look up getline so you can retrieve the data from property file

3. Main part of code will be to simply check the values are not null in the required fields

The last step is not so complicated in awk as a simple if can test each field you require to look at.

Let us know if you get stuck
 
Old 12-21-2011, 05:51 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
I'd also point out that this
Code:
cut –f 1,3,4 –d ‘|’ Jewson.csv
doesn't make sense. Here the separator is a pipe, but the file extension is csv (comma sep var).
You need to decide which. If pipe (ie '|') then fname.psv.
Strictly speaking you don't HAVE to match the file ext to the content, but it does save confusion later...

PS
Code:
While read LINE ; do
'while' must be in lowercase; *nix is case sensitive...

Last edited by chrism01; 12-21-2011 at 05:54 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing lines in two files? needhelp12 Linux - Newbie 3 11-12-2011 11:48 PM
Comparing two files ab52 Programming 10 12-01-2010 11:08 AM
comparing files newbiesforever Linux - Software 3 07-07-2010 03:20 PM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 09:15 PM
Comparing 2 Files xianzai Programming 2 05-23-2004 11:50 AM


All times are GMT -5. The time now is 06:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration