•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,446 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,659 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1495 | Replies: 10
![]() |
Cool. What do you have so far, and what problem are you having with it.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
What do you mean by this? This forum is for Linux/Unix Shell Scripting, not Windows Batching (unless things have changed).
As far as doing the comparisons, an easy, but not necessarily performant way is a simple grep command.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Oct 2007
Posts: 306
Reputation:
Rep Power: 2
Solved Threads: 29
a's got 100
b's got 9
you need the 91 uniques - I'll put 'em in c.txt
Sorry - just needed to drop a post somewhere - it's been a while
, Mike
b's got 9
you need the 91 uniques - I'll put 'em in c.txt
while read line
do
grep $line b.txt >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo $line >>c.txt
fi
done <a.txtSorry - just needed to drop a post somewhere - it's been a while

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
•
•
•
•
a's got 100
b's got 9
you need the 91 uniques - I'll put 'em in c.txt
while read line do grep $line b.txt >/dev/null 2>&1 if [ $? -ne 0 ] then echo $line >>c.txt fi done <a.txt
Sorry - just needed to drop a post somewhere - it's been a while
, Mike
Its actually easier, if with a few more file operations.
cp b.txt /tmp/b1.txt while read line do grep -v $line /tmp/b1.txt >/tmp/b2.txt 2>/dev/null mv -f b2.txt b1.txt done <a.txt mv b1.txt c.txt
Last edited by masijade : Nov 17th, 2007 at 5:58 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Oct 2007
Posts: 22
Reputation:
Rep Power: 2
Solved Threads: 0
Masijade,
I finished the file comparison in MS Access.But I am trying to do the same file comparison using Shell script...Thats why posted you a thread..
I didn't understand this line in your script :
grep -v $line /tmp/b1.txt >/tmp/b2.txt 2>/dev/null
Can you please explain?
Thanks in advance
Regards
dave.....
I finished the file comparison in MS Access.But I am trying to do the same file comparison using Shell script...Thats why posted you a thread..
I didn't understand this line in your script :
grep -v $line /tmp/b1.txt >/tmp/b2.txt 2>/dev/null
Can you please explain?
Thanks in advance
Regards
dave.....
•
•
Join Date: Oct 2007
Posts: 22
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
a's got 100
b's got 9
you need the 91 uniques - I'll put 'em in c.txt
while read line do grep $line b.txt >/dev/null 2>&1 if [ $? -ne 0 ] then echo $line >>c.txt fi done <a.txt
Sorry - just needed to drop a post somewhere - it's been a while
, Mike
Mike,
why are you using ">/dev/null 2>&1" in your script?
What condition you are checking in your "if" loop?
Regards
Dave
Last edited by dave_nithis : Nov 19th, 2007 at 7:57 am.
•
•
•
•
Masijade,
I finished the file comparison in MS Access.But I am trying to do the same file comparison using Shell script...Thats why posted you a thread..
I didn't understand this line in your script :
grep -v $line /tmp/b1.txt >/tmp/b2.txt 2>/dev/null
Can you please explain?
Thanks in advance
Regards
dave.....
grep -v means to match everything except the next text (you should probably place $line in quotes) from the the first file listed (b1.txt) and output it to the second file listed ( > b2.txt) and ignore any error messages (2>/dev/null).
The next line then moves b2.txt to b1.txt so you can repeat the procedure with the next line. Once you have gone through all lines, b2.txt contains all lines from b that were not in a.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Clean Previous Next Script for MySQL results (PHP)
- The name for the Resize Button to ad to Script (HTML and CSS)
- Random Programming Script (Computer Science and Software Design)
- Importing SQL Script File - Urgent !! (Database Design)
- Script problems with IE (Web Browsers)
- Help with shell script to auto gzip a .sql dump after backup (Shell Scripting)
- Adding mutiple PC's to an OU via script? (Windows NT / 2000 / XP / 2003)
- Table of Contents Script (Java)
- ASP slow-down server script (ASP)
Other Threads in the Shell Scripting Forum
- Previous Thread: shell script
- Next Thread: need help with figuring out sizeof in bash script



Linear Mode