Find the answer to your Linux question:
Results 1 to 2 of 2
I need some help with the script, whenever I run it, the program just seems to hang. When I press ^C it seems to have run through the first line ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Posts
    3

    Bash script with sed

    I need some help with the script, whenever I run it, the program just seems to hang. When I press ^C it seems to have run through the first line but doesn't continue.

    By the way, I know the script is overkill at the moment, but it's just the beginning to a much larger script.

    Script:
    Code:
    #!/bin/bash
    cat test | while read THELINE
    LINENUM=0
    do
      OK_USER=(root admin)
      MYUSER=$(echo $THELINE | cut -d, -f1)
      MYPROC=$(echo $THELINE | cut -d, -f11)
    for ((i=0; i<${#OK_USER[@]}; i++))
      do
        LINENUM=$((LINENUM+1))
        if [ "$MYUSER" =  "${OK_USER[$i]}" ]; then
          sed -i "${LINENUM}d" test
        fi
      done
    
    done
    cat test;
    In the test file I have:
    root
    admin
    user
    bob
    joe
    five



    What it's supposed to do is run through the file and remove all of the users which are defined in the array (root and admin).


    Results should be:
    ./script

    user
    bob
    joe
    five


    Thank you

  2. #2
    Just Joined!
    Join Date
    Feb 2009
    Posts
    3
    Nevermind, I got it solved in a much simpler way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...