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 ...
- 02-14-2009 #1Just 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:
In the test file I have: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;
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
- 02-14-2009 #2Just Joined!
- Join Date
- Feb 2009
- Posts
- 3
Nevermind, I got it solved in a much simpler way


Reply With Quote