output words between sentences SED

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

# awk -F 'start' 'BEGIN{RS="end"; OFS="\n"; ORS=""} {print $2}' test.txt
or
# sed -n '/^start/,/^end/{/LABEL$/!p}' test.txt

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

Just leave those as is, just change start and end

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.

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)"

Both works good. Thank you guys :b: 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)}'

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

Thanks, you rule! :smiley: 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/'