[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RES: [shell-script] pegar linha e alterar
From: |
Alexandre Abreu |
Subject: |
Re: RES: [shell-script] pegar linha e alterar |
Date: |
Fri, 22 Apr 2005 10:53:51 -0300 |
Olá,
Fala ai Luiz! :)
Segue minha solução para seu problema, é feito em awk, é um típico
exemplo para, possivelmente, discutirmos:
------------ switch.sh --------------
#!/bin/sh
[ $# -eq 2 ] || {
echo "Sintaxe: $0 <user> <arquivo>"
exit 1
}
FILE="$2"
awk -v USER="$1" -v FILE="$2" '
BEGIN {
"mktemp" | getline TMP
CHANGE=0
}
{
if($0 ~ "^ON[|]" USER) {
CHANGE=1
print "Found entry: " $0
print "Changing..."
sub("^ON","OFF")
}
print $0 >> TMP
}
END {
if(CHANGE)
CMD="mv -f " TMP " " FILE
else
CMD="rm -f " TMP
if(!system(CMD))
exit 1
}
' $FILE
-------------------- end switch.sh -----------------------
Um abraço
--
Alexandre de Abreu, GCUX, RHCE
Proteus Security Systems