cat results.txt | grep -E "(([a-z]\.txt)|((success)|(error)!!))" | tr -d '\n' | sed 's/!!/!!\n/'
should do it. You might have to replace \n
with a literal newline though.
David Kanarek
2010-02-25 07:07:59
cat results.txt | grep -E "(([a-z]\.txt)|((success)|(error)!!))" | tr -d '\n' | sed 's/!!/!!\n/'
should do it. You might have to replace \n
with a literal newline though.
$ cat file
a.txt
{some
blah
data}
success!!
b.txt
{some data}
success!!
c.txt
{some data}
error!!
$ awk 'BEGIN{ FS="[{}]|\n";RS=""}{gsub(/!!/,"",$NF);print $1":"$NF}' file
a.txt:success
b.txt:success
c.txt:error
Update:
$ awk -vRS= -vFS="\n" '{print $1":"$NF}' file
a.txt:success!!
b.txt:success!!
c.txt:error!!
That works for me:
cat result.txt | xargs |sed 's/\ {[^}]*}/:/g' | sed 's/!! /\n/g'
a.txt: success
b.txt: success
c.txt: error!!
awk:
BEGIN {
state=0
}
state==0 && /.txt$/ {
filename=$0
state=1
next
}
state==1 && /!!$/ {
print filename ": " gensub(/!!$/, "", $0)
state=0
next
}
You can use the following way also.
sed -e 's/^{some data}$//g;/^$/d;' results.txt | sed '$!N;s/\n/: /'