Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

join lines (2 or 3) & extracting fileds that have a specific word in i

Status
Not open for further replies.

ancadmihai

Technical User
Apr 26, 2007
4
SE
hi all

please give me a hand in solving the following problem

i have a file that contains the following lines


40765300012 226030100315050 CONNECTED AVAILABLE
OCSI-1 OFA-20 PWD-0000 OICK-20
SCHAR-4-0
40765300023 226030100315061 CONNECTED AVAILABLE
OCSI-1 OFA-20 PWD-0000 OICK-20
SCHAR-4-0
40765300031 226030100315069 CONNECTED AVAILABLE
OCSI-1 OFA-20 PWD-0000 OICK-20
SCHAR-4-0
40765300039 226030100315077 CONNECTED AVAILABLE



each msisdn(4076******) may have a OICK & SCHAR or a SCHAR. each of this info is printed in diferent lines



i need a script that has as an output lines that look like this

4076****** oick=** (if it exists) SCHAR-*-0(where * may be 8 or 4)


please give me a hand. i've managed to give myself a head acke with this.

thank's a lot in advance.
 
How about this sed soln? Awk would probably be better.
Code:
#! /bin/sed -nf

1{
  /^4076/{s/ .*//;h;}
}
1!{
/^4076/{x;s/\n//g;p;g;s/ .*//;h;}
/^OCSI/{s/.*\( OICK.*\)/\L\1/;H;}
/^SCHAR/{s/^/ /;H;}
}
${
/^4076/{p;q}
g;s/\n//g;p
}

$ /path/sedfile /path/input

Cheers,
ND [smile]
 
An awk solution:

Code:
awk '
        function printrec () { print num,oick,schar ; num=oick=schar="" }
        /^[0-9]/ && NR>1 { printrec() }
        /^[0-9]/ { num=$1 }
        /^OCSI/ { oick=$NF ; sub("OICK-","oick=",oick) }
        /^SCHAR/ { schar=$1 }
        END { printrec() }
' inputfile > outputfile

Annihilannic.
 
thanks a lot annihilannic :D
you;ve saved my day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top