wrwe
December 16, 2008, 2:45pm
1
Hi, i need to delete every thing ecept sentences between known prases lets say
i have
Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)
i need information between
Login OK: [
and
] (from
what is vyce6220. between
client
and
port
between
cli
and
)
what is 001644fc4838
so the output should be :
vyce6220 LINKSYS3 001644fc4838
i have tried
sed 's#.*Login OK: [\(.*\)] (.*#\1#' radoms.txt
but it doesn't work because of [ but i need login name whithout them and the secon thing is that i can't make more betweens to find
Ikon
December 16, 2008, 2:50pm
2
# awk -F 'start' 'BEGIN{RS="end"; OFS="\n"; ORS=""} {print $2}' test.txt
or
# sed -n '/^start/,/^end/{/LABEL$/!p}' test.txt
wrwe
December 16, 2008, 3:11pm
3
ok i understand start and end but what is LABEL$ and !p ?
Hi,
choose one of two ways:
sed 's/.*OK: \[\([^]]*\).*/\1/' <<< \
"Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)"
or much easier:
IFS="[]" && read 1 2 3 <<< \
"Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)"
echo $2
HTH Chris
Ikon
December 16, 2008, 3:21pm
5
Just leave those as is, just change start and end
tadasvu
December 16, 2008, 3:30pm
6
Hi,
choose one of two ways:
sed 's/.*OK: \[\([^]]*\).*/\1/' <<< \
"Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)"
or much easier:
IFS="[]" && read 1 2 3 <<< \
"Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)"
echo $2
HTH Chris
thanks it works good, but i need complex comand of that i dont understand how to do that. taht you can look between word and word2 and also at the same command between word3 and word4.
tadasvu
December 16, 2008, 3:35pm
7
first whith !p:
p: Event not found.
whithout !p
: command } expects up to 0 address(es), found 1
echo 'Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838' | nawk -F'([]])|([[])|([() ])' '{ print $12, $17, $NF}'
Oh sorry, overlooked the rest. This should work:
sed 's/.*OK: \[\([^]]*\).*client \([^ ]*\).*cli \(.*\)./\1 \2 \3/' <<< \
"Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)"
wrwe
December 16, 2008, 3:56pm
10
Both works good. Thank you guys Now the problem with the mac structure should be separated with : Is it posible to convert mac to xx:xx:xx:xx at the same command or i should look for something that now looks for fird word in a sentence and converts.
echo 'Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838' | nawk -F'([]])|([[])|([() ])' '{ print $12, $17, substr($NF,1,3) ":" substr($NF,4,3) ":" substr($NF,7,3) ":" substr($NF,10)}'
wrwe
December 16, 2008, 5:41pm
12
vgersh99:
echo 'Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838' | nawk -F'([]])|([[])|([() ])' '{ print $12, $17, substr($NF,1,3) ":" substr($NF,4,3) ":" substr($NF,7,3) ":" substr($NF,10)}'
very useful comand. How can i make it work with file? isit posible tu do that if in text are some keywords lets say Login OK: whan do the command if not no.
/Login OK:/ { }
nawk -F'([]])|([[])|([() ])' '/Login OK:/ { print $12, $17, substr($NF,1,3) ":" substr($NF,4,3) ":" substr($NF,7,3) ":" substr($NF,10)}' myFile
wrwe
December 17, 2008, 10:53am
14
vgersh99:
nawk -F'([]])|([[])|([() ])' '/Login OK:/ { print $12, $17, substr($NF,1,3) ":" substr($NF,4,3) ":" substr($NF,7,3) ":" substr($NF,10)}' myFile
Thanks, you rule! but one last question i need in one word lets say it is $17 replace LINK to something else or in mac adress if it comes like this 00-00-00-00-00 - replace with : maby sub should help ? sub(/-/, ":") but where should i put it? and how i should know that it have to work just with lets say $17 word
something along these lines?
nawk -F'([]])|([[])|([() ])' -v smt4link='SomethingElse' '/Login OK:/{ sub("LINK", smt4link, $17); if ($NF ~ /^..-..-..-..-..$/)gsub("-", ":", $NF); else $NF=substr($NF,1,3) ":" substr($NF,4,3) ":" substr($NF,7,3) ":" substr($NF,10); print $12, $17, $NF}' myFile
echo "Thu Dec 4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)" |
sed 's/\(.*Login OK: \[\)\(.*\)\(\].*from.*client\)\(.*\)\(port.*cli\)\(.*\)\().*\)/\2\4\6/'