Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-30-2012, 12:50 PM   #1
Registered: Jun 2012
Posts: 47

Rep: Reputation: Disabled
Bash - find something in one file and if it doesn't exist in the second file print.

I'm trying to compare two files. I want to grab the first line in the first file and check second file to see if it exists. If it does not exist in second file then print. And so on for every line in file1.

Right now i don't get any output stuck into my output file. I'm sure this is easy and i've just stared at it too long.


while read $line
grep $line $file2 > /dev/null
if [ $? -ne 0 ]; then
echo $line >> output.txt

done < $file1
Old 08-30-2012, 01:06 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,243
Blog Entries: 15

Rep: Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320
while read line

NOT: while read $line

In the first you're declaring the variable which can be used as $line later in the script. In the latter you're attempting to use the variable and likely getting a null since you haven't previously declared it.
Old 08-30-2012, 01:17 PM   #3
Registered: Jun 2012
Posts: 47

Original Poster
Rep: Reputation: Disabled
OMG. Well thank you. I was SO freaking close. Always has to be something dumb.


bash, bash scripting

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
[SOLVED] Why config.h file doesn't exist? stgmvaragi Fedora 4 08-02-2010 05:49 AM
scp help! It says my file doesn't exist! Katie59 Linux - Newbie 5 02-18-2010 05:31 PM
Folder $(gcc -print-libgcc-file-name) doesn't exist. 5.7 clonas Linux From Scratch 8 10-24-2008 07:08 PM
Need to find if a matching file exist from a list of possible file names wit_273 Linux - General 5 10-25-2007 09:47 AM
trying to redirect text to a file to cat at later point. says file doesn't exist. dr_zayus69 Programming 1 10-02-2005 08:10 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:38 PM.

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