LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Closed Thread
  Search this Thread
Old 06-17-2007, 04:12 PM   #1
bhandu
LQ Newbie
 
Registered: Mar 2006
Posts: 22

Rep: Reputation: 15
Script for scaning files


I have developed a shell script which will scan two files and then put the similar records in a third file.The script is follows


rm $filename3
touch $filename3

exec < $filename1

while read line
do
exec <filename2
while read line1
do
if [ $line -eq $line1 ]
echo $line >> filename3
end if
done
done

But the above shell script is not working.
Could anyone help me out?
 
Old 06-17-2007, 06:25 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You seem to be fast and loose with the "$" character.

Code:
exec < $filename1
Are you trying to source a file here? The variable filename1 is undefined as well.
. $filename1

Code:
while read line1
This will read a line of input from stdin and place it in the variable line1
The read command should rarely be used in bash programs. It's better to pipe the output of one command into the input of another using the proper utilities to do the job.

Code:
exec <filename2
Are you trying to source a file named "./filename2"? Did you mean:
. $filename2
However filename2 would be undefined. Also the exec command will replace this shell with the program indicated by $filename2

Code:
do
if [ $line -eq $line1 ]
echo $line >> filename3
end if
If you wanted to output differing entries in two files, you could use the diff or comm commands instead.
The comm command works on sorted lists and prints out 3 columns. The first is items uniq to list1. The second is items uniq to list2, and the third is items common to both. You can suppress the output of the columns you don't want.

You may also be confusing the "exec" command with the eval command if you are trying to execute a line of code contained in a variable.

Last edited by jschiwal; 06-17-2007 at 06:45 PM.
 
Old 06-17-2007, 07:10 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Dupe of
http://www.linuxquestions.org/questi...d.php?t=562272
and
http://www.linuxquestions.org/questi...d.php?t=562490
 
Old 06-17-2007, 07:54 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script for scaning files bhandu Linux - General 3 06-16-2007 09:06 PM
Scaning devices on the network GSalah Linux - Networking 7 07-02-2006 08:13 AM
Scaning disk mp4-10 Linux - Software 3 03-22-2005 10:40 AM
I think someone is scaning me Joey.Dale Linux - Networking 6 01-02-2004 05:20 PM
Postfix/amavisd-new virus scaning only thesnaggle Linux - Software 0 12-16-2003 10:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:18 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
Open Source Consulting | Domain Registration