LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 08-30-2012, 12:50 PM   #1
Rogue45
Member
 
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.

#!/bin/bash
file1=/home/user/Documents/file1.txt
file2=/home/user/Documents/file2.txt


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

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

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
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
Rogue45
Member
 
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.
 
  


Reply

Tags
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


All times are GMT -5. The time now is 12:07 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration