extract a string after a pattern using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract a string after a pattern using sed
# 1  
Old 10-11-2008
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.
Code:
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
# 2  
Old 10-11-2008
please post in the appropriate forum for your question! moved to shell programming. this is also a dup of https://www.unix.com/unix-dummies-que...rep-print.html

thread closed!

Last edited by DukeNuke2; 10-11-2008 at 04:54 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Extract a pattern using sed or cut

Hi, Need help to extract a pattern using sed or cut or any other means. Input 'name1',1234567890 'name2',2222222222 'name3',3333333333 Expected output name1,1234567890 name2,2222222222 name3,3333333333 (3 Replies)
Discussion started by: mukulverma2408
3 Replies

2. Shell Programming and Scripting

Pattern Match & Extract from a string

Hi, I have long string in 2nd field, as shown below: REF1 | CLESCLJSCSHSCSMSCSNSCSRSCUDSCUFSCU7SCV1SCWPSCXGPDBACAPA0DHDPDMESED6 REF2 | SBR4PCBFPCDRSCSCG3SCHEBSCKNSCKPSCLLSCMCZXTNPCVFPCV6P4KL0DMDSDSASEWG I have a group of fixed patterns which can occur in these long strings & only... (11 Replies)
Discussion started by: karumudi7
11 Replies

3. Shell Programming and Scripting

extract part of string using sed

Hi, I have the following string and I need to extract the date from it: TextHere,2012/07/11,1 I tried using sed: sed -n 's#^.*\({4}/{2}/{2}\).*$#\1#p' But it doesn't return anything. The following line doesn't even return '2012': sed -n 's/^.*\({4}\).*$/\1/p' I used to use grep -o... (6 Replies)
Discussion started by: Subbeh
6 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. Shell Programming and Scripting

Using SED to extract a word or string.

I am working with the ksh shell in HP UNIX and I am attempting to extract a word, beginning with a particular string and ending at the first space. for example I want to extract the word or string MS_RECENT_ACTIVITY from the following string " This has been entered in MS_RECENT_ACTIVITY the... (2 Replies)
Discussion started by: simpletech369
2 Replies

6. Shell Programming and Scripting

extract a string within a string using a pattern

hi all, i have a file name using the following pattern: PREFIX: AR SOURCE: LEGACY DATETIME: YYYYMMDD_HH24MISS SUFFIX: .txt sample filename: AR_LEGACY_20101104_105500.txt i want to extract the source which is LEGACY in this case. how do i do this using shell? thanks. (4 Replies)
Discussion started by: adshocker
4 Replies

7. Shell Programming and Scripting

[sed] extract words from a string

Hi, One of the scripts creates logs in the format: progname_file1.log.20100312020657 where after file the number could be from 1 to 28 and after log. the date is attached in the format YYYYMMDDHHMISS progname_file<1-28>.log.YYYYMMDDHHMISS. Now I want to discard the .20100312020657... (7 Replies)
Discussion started by: dips_ag
7 Replies

8. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

9. Shell Programming and Scripting

extract string portion using sed

Hi All I have 3 files as listed below and highlighted in bold the portions of the filenames I need to extract: TOS_TABIN218_20090323.200903231830 TOS_TABIN219_1_20090323.200903231830 TOS_TABIN219_2_20090323.200903231830 I tried source_tabin_name=`echo $fname | sed 's/_.*//'` but I... (6 Replies)
Discussion started by: santam
6 Replies

10. Shell Programming and Scripting

Please help! Sed extract a pattern

I am trying to extract "securitySettings" out of line: <a ref ="http://localhost:5654/securitySettings"> using sed as follows: name = `grep "localhost" file.html | sed -n 's/.**\/\(.*)/\">/\1/p'` But it didn't run, seems have some syntax error. Do anybody knows why? Thank you very... (11 Replies)
Discussion started by: zhen
11 Replies
Login or Register to Ask a Question