Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 01-19-2014, 04:38 PM   #1
LQ Newbie
Registered: Jan 2014
Posts: 2

Rep: Reputation: Disabled
Deleting lines from a file in a bash script


I'm writing a bash script where I need to set some variables. The variables will be set if a line exists in a specific file.

I'm planning on creating one file with a list of lines, e.g.:


And I'll have a second file which may read:


I want to create a new file by removing the matching lines between the two original files, so just leaving me with:


...And then use this specific file to set my variables, i.e. set a variable for any words that exist in this file.

What's the best way for me to do this? I was playing around with sed, but not sure how to work it to best fit.

Thanks in advance!
Old 01-19-2014, 05:18 PM   #2
Senior Member
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
Maybe something as simple as:

cat devicedump.txt | grep -vFf pattern_file.txt > output.txt
<edit>Sorry, forgot the second part of your question, maybe just copy the output file to a temporary file and append or prepend 'something=<line>' or '<line>=something' to create variable assignments, then just source it in your script to set the variables?</edit>

Last edited by kbp; 01-19-2014 at 05:22 PM.
1 members found this post helpful.
Old 01-19-2014, 09:20 PM   #3
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 664

Rep: Reputation: 81
we would be happy to help you provided that you Show us something you tried to play with to achieve this..

well for a hint:

while read line
done < input_file
Old 01-27-2014, 08:30 AM   #4
LQ Newbie
Registered: Jan 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
I actually just set the variables and unset if they existed elsewhere - same end result. Probably inefficient code but it seems to work!

also not with the code now so can't post it I'm afraid.

thanks for the replies though!!


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash script:: How to make columns from lines inf file turdus Programming 7 11-29-2011 07:19 PM
Basic bash script question re: file size or # of lines in a file the_fornicator Programming 6 09-03-2009 10:41 AM
Need a bash shell script which will delete lines from file scjohnie Linux - Newbie 1 09-13-2008 09:51 PM
bash script to remove the blank lines in the file naveensankineni Programming 7 03-25-2008 09:34 PM
Can't get lines of a file with a Bash script.. barisdemiray Programming 2 08-11-2004 01:42 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:05 AM.

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