views:

117

answers:

7
A: 

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
+2  A: 
$ 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!!
ghostdog74
You *might* have taken his curly brackets too literally :)
vladr
yes, you might be right. but who knows ;), in any case, the second version can be used.
ghostdog74
+1  A: 

That works for me:

cat result.txt | xargs |sed 's/\ {[^}]*}/:/g' | sed 's/!! /\n/g'

a.txt: success
b.txt: success
c.txt: error!!
Enrico Carlesso
+3  A: 

awk:

BEGIN {
  state=0
}

state==0 && /.txt$/ {
  filename=$0
  state=1
  next
}

state==1 && /!!$/ {
  print filename ": " gensub(/!!$/, "", $0)
  state=0
  next
}
Ignacio Vazquez-Abrams
A: 

cat a.txt | tail -1

+2  A: 

You can use the following way also.

sed -e 's/^{some data}$//g;/^$/d;' results.txt | sed '$!N;s/\n/: /'
rekha_sri
A: 
awk '{print $1": "$4}' RS="\n\n" results.txt