The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 10-11-2008
gunaah gunaah is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 7
extract a string after a pattern using sed

I have a very large file and each line has a pattern and it is not position specific. I need to extract the string after the pattern

****MI* is the pattern in the red color
12 digit number is the sting value in the green color and it ends with ~

e.g.

5~NM1*IL*1*ARROYO*JESUS****MI*010001990802~N3*11300 WOOD ST*APT J~
***15~NM1*IL*1*HILARIO VALENCIA*ISMAEL****MI*010002846144~N3*9242
***15~NM1*IL*1*SALDANA*NICOLASA****MI*010000817902~N3*12348 N HIGH
*P*18****6***15~NM1*IL*1*CARRILLO*OSCAR****MI*010002858693~N3*8000
5~NM1*IL*1*MENDOZA*KIARA****MI*010001985968~N3*9119 DECOY CT~N4*LA
*18****6***15~NM1*IL*1*NAVARRETTE*JADE****MI*010001670093~N3*5075
5~NM1*IL*1*GARCIA*FERNANDO****MI*010001922131~N3*5811 KAREN PL~N4*
*6***15~NM1*IL*1*RATTERO*JAQUELINE****MI*010001773030~N3*253 E MCK
18****6***15~NM1*IL*1*ROSAS*ALONDRA****MI*010001731780~N3*1326 1/2
18****6***15~NM1*IL*1*RAMOS-HERNANDEZ*ROSALINDA****MI*010002883575
18****6***15~NM1*IL*1*YU*LARRY****MI*010001974928~N3*2817 WENDELL
18****6***15~NM1*IL*1*YU*LARRY****MI*010001974928~N3*2817 WENDELL
***15~NM1*IL*1*SOTO*RAUL****MI*010001882921~N3*1318 NORTH HELM AVE
***15~NM1*IL*1*LINARES*LUIS****MI*010000877519~N3*3489 E MCKINLEY
**6***15~NM1*IL*1*CALDERON*GERARDO****MI*010000744686~N3*1522 AMAD
010001974928~N3*2817 WENDELL AVE~N4*RICHMOND*CA*948041361~DMG*D8*1

cat c2.txt | tr '~' '\n' | grep '****MI'

I am not getting desired result

Pls. help

Thanks