Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

Solved: UNIX Shell Script HELP !!!


(!)

cowman76's Avatar
cowman76 cowman76 is offline
Computer Specs
Junior Member with 8 posts.
THREAD STARTER
 
Join Date: Jun 2007
Experience: Intermediate
21-Jun-2007, 06:58 AM #1
Question Solved: UNIX Shell Script HELP !!!
I am trying to create a script which removes a list of servers from a text file for a hosts file ???

I have tried all kinds of combinations with if statements but cant seem to find anything that works ???

all i want to do is remove a list of servers in one text from another text file.
Sounds easy but any help will be appreciated.
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
25-Jun-2007, 03:55 PM #2
Post your existing code and I can probably help you.
headscan69's Avatar
headscan69 headscan69 is offline
Computer Specs
Member with 55 posts.
 
Join Date: Jun 2007
Location: Wisconsin
Experience: Advanced
26-Jun-2007, 02:15 PM #3
This should give a start. If you want to test this out. If it works to your liking then add another line at the end.... mv -f hosts.temp hosts

for filename in remove.hosts
do
cat $filename | \
while read line
do
sed -e 's/'"$line"'/ /g' hosts > host.temp
done
done

Last edited by headscan69; 27-Jun-2007 at 09:46 AM..
ghostdog74's Avatar
ghostdog74 ghostdog74 is offline
Member with 146 posts.
 
Join Date: Dec 2005
26-Jun-2007, 02:28 PM #4
Quote:
Originally Posted by headscan69
This should give a start. If you want to test this out. If it works to your liking then add another line at the end.... mv -f hosts.temp to hosts.

for filename in remove.hosts
do
cat $filename | \
while read line
do
sed -e 's/'"$line"'/ /g' hosts > host.temp
done
done
why use cat when the while loop can take in input?
Code:
while read line
do
 ....
done < filename
headscan69's Avatar
headscan69 headscan69 is offline
Computer Specs
Member with 55 posts.
 
Join Date: Jun 2007
Location: Wisconsin
Experience: Advanced
26-Jun-2007, 03:53 PM #5
Good question. Can just specify filename and remove the other associated lines.
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
27-Jun-2007, 05:26 PM #6
I probably would have done a reverse grep. But sed is good as well.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑