You are not logged in.

#1 2010-04-22 10:09:33

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

[solved] Remove words from file using a list variable?????

Is it possible with bash, to create a script that will scan a text file and remove words that are set in a list?
I have a file with words like so:
word1
word2
word3

I would like to be able to set script to scan file and remove only the words (and spaces left) that are in a list,
that is inside script. Is this possible???

Last edited by orphius1970 (2010-04-22 12:05:45)


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

#2 2010-04-22 11:06:51

vacant
Member
From: downstairs
Registered: 2004-11-05
Posts: 816

Re: [solved] Remove words from file using a list variable?????

concatentate all the words in the list then use sed with "or" expressions (|), e.g

$ sed s/"hal\|netmask"// /etc/rc.conf

Offline

#3 2010-04-22 11:21:04

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

Re: [solved] Remove words from file using a list variable?????

sorry I am new to scripting and Have NEVER used sed.
Can you explain a little better?

Ok i tried it and understand a little better. However,
It left space behind. How do I fix that?
Also, how do I get it to save the file with the changes?
Sorry If I seem so noobie

Last edited by orphius1970 (2010-04-22 11:27:18)


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

#4 2010-04-22 11:53:12

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: [solved] Remove words from file using a list variable?????

grep -vf words.list /path/to/file > /path/to/cleaned-file

Offline

#5 2010-04-22 12:05:27

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

Re: [solved] Remove words from file using a list variable?????

thank you fukawi2 !
I can work with that


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

Board footer

Powered by FluxBB