1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: UNIX Shell Script HELP !!!

Discussion in 'Software Development' started by cowman76, Jun 21, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. cowman76

    cowman76 Thread Starter

    Joined:
    Jun 14, 2007
    Messages:
    8
    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.
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    Post your existing code and I can probably help you.
     
  3. headscan69

    headscan69

    Joined:
    Jun 25, 2007
    Messages:
    55
    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
     
  4. ghostdog74

    ghostdog74

    Joined:
    Dec 7, 2005
    Messages:
    146
    why use cat when the while loop can take in input?
    Code:
    while read line
    do
     ....
    done < filename
    
     
  5. headscan69

    headscan69

    Joined:
    Jun 25, 2007
    Messages:
    55
    Good question. Can just specify filename and remove the other associated lines.
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    I probably would have done a reverse grep. But sed is good as well.
     
  7. Sponsor

As Seen On
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/586685