Extract and parse data between two strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract and parse data between two strings
# 1  
Old 03-24-2010
Extract and parse data between two strings

Hi , I have a billing CDR file which is separated by “!”. I need to extract and format data between the starting (“!”) and the end of the line (“1.2.1.8”). These two variables are permanent tags to show begin and end.

! TICKET NBR : 2 ! GSI : 101 ! 3100.2.112.1 24/03/2010 00:41:14 ! 3100.2.105.6 Mobility ! 1.2.1.5 24/03/2010 00:41:14 ! 3100.2.19.5 302619135190023 ! 3100.2.70.15 101R=241234541717 ! 3100.2.19.7 99135190023 ! 3100.2.984.50 A18 ! 3100.2.104.4 acc_22640957031006 ! 3100.2.24.1 20 ! 3100.2.140.1 100 ! 3100.2.142.1 100 ! 100.6.5.1 1 ! 3100.2.106.1 SMS_ALWAYS_ALLOWED ! 100.6.5.2 1 ! 449032008 labl301 ! 3100.2.22.1 SMSMT ! 3100.2.20.1 9135190023 ! 3100.2.13.1 0.00 ! 3100.2.14.2 0 ! 1.2.1.8

(1) On the starting, the first two parameters are separated by semicolon (“:”) but still separated by “!”
(2) And, rest of them are separated by 4 digit number (ex: X.X.X.X <blank space> Output)” followed by return result. I want to have the output like

TICKET NBR : 2
GSI : 101
3100.2.112.1 : 24/03/2010 00:41:14
3100.2.105.6 : Mobility
1.2.1.5 : 24/03/2010 00:41:14
.
.
.(Last 3 )
3100.2.20.1: 9135190023
3100.2.13.1 : 0.00
3100.2.14.2 : 0


I am looking for a single awk/sed command to parse this information. The above example is a single line output. Any help will be greatly appreciated.
Gamini
# 2  
Old 03-24-2010
Code:
tr '!' "\n" <file

# 3  
Old 03-24-2010
Code:
awk '{gsub("[ ]*! ","\n")}1' CDRfile | awk '!/: /{sub(" "," : ")}NF>1'

# 4  
Old 03-25-2010
Thanks guys
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Issue when using egrep to extract strings (too many strings)

Dear all, I have a data like below (n of rows=400,000) and I want to extract the rows with certain strings. I use code below. It works if there is not too many strings for example n of strings <5000. while I have 90,000 strings to extract. If I use the egrep code below, I will get error: ... (3 Replies)
Discussion started by: forevertl
3 Replies

2. Shell Programming and Scripting

Parse Page Source and Extract Links

Hi Friends, I have a bunch of URLs. Each URL will open up an abstract page. But, the source contains a link to the main PDF article. I am looking for a script to do the following task 1. Read input file with URLs. 2. Parse the source and grab all the lines that has the word 'PDF'.... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

3. Shell Programming and Scripting

Extract two strings from a file and create a new file with these strings

I have the following lines in a log file. It would be great if some one can help me to create a new file with the just entries in the below format. 66.150.161.195 HPSAC=Z05 66.150.161.196 HPSAC=A05 That is just extract the IP address and the string DPSAC=its value 66.150.161.195 -... (1 Reply)
Discussion started by: Tuxidow
1 Replies

4. Shell Programming and Scripting

Extract/Parse information from html (website)

Hello, I want to extract some informations from a html (website, http://www.energiecontracting.de/7-mitglieder/von-A-Z.php?a_z=B&seite=2 ) file and save those in a predefined format (.csv).. However it seems that the code on that website is kinda messy and I can't find a way to handle it... (5 Replies)
Discussion started by: TehOne
5 Replies

5. Shell Programming and Scripting

Extract and parse XML data (statistic value) to csv

Hi All, I need to parse some statistic data from the "measInfo" -eg. 25250000 (as highlighted) and return the result into line by line, and erasing all other unnecessary info/tag. Thought of starting with grep "measInfoID="25250000" but this only returns 1 line. How do I get all the output... (8 Replies)
Discussion started by: jackma
8 Replies

6. Shell Programming and Scripting

Search and Extract data between two strings

hi, In a given directory, i need to search for a string (eg:ABCD). For a given file, i have to extract the text between START and END strings . I need to extract all the text between START and END and there can be multiple START and END in a file. Sample: There is a directort... (3 Replies)
Discussion started by: flamingo_l
3 Replies

7. Shell Programming and Scripting

Extract data between two strings

Hi , I have a billing CDR file which has repeated lines as indicated below and I need to extract data between two strings (i.e.: <?> and </?>). Eventually, map that information with the corresponding field. I'm new to unix, any help will be greatly appreciated. Gamini Input (single line): !... (3 Replies)
Discussion started by: jaygamini
3 Replies

8. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

9. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

10. Shell Programming and Scripting

Parse apart strings of comma separated data with varying number of fields

I have a situation where I am reading a text file line-by-line. Those lines of data contain comma separated fields of data. However, each line can vary in the number of fields it can contain. What I need to do is parse apart each line and write each field of data found (left to right) into a file.... (7 Replies)
Discussion started by: 2reperry
7 Replies
Login or Register to Ask a Question