Sponsored Content
Top Forums Shell Programming and Scripting Extract and parse data between two strings Post 302407043 by jaygamini on Wednesday 24th of March 2010 11:54:35 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Cache(3pm)						User Contributed Perl Documentation						Cache(3pm)

NAME
Tie::Cache - LRU Cache in Memory SYNOPSIS
use Tie::Cache; tie %cache, 'Tie::Cache', 100, { Debug => 1 }; tie %cache2, 'Tie::Cache', { MaxCount => 100, MaxBytes => 50000 }; tie %cache3, 'Tie::Cache', 100, { Debug => 1 , WriteSync => 0}; # Options ################################################################## # # Debug => 0 - DEFAULT, no debugging output # 1 - prints cache statistics upon destroying # 2 - prints detailed debugging info # # MaxCount => Maximum entries in cache. # # MaxBytes => Maximum bytes taken in memory for cache based on approximate # size of total cache structure in memory # # There is approximately 240 bytes used per key/value pair in the cache for # the cache data structures, so a cache of 5000 entries would take # at approximately 1.2M plus the size of the data being cached. # # MaxSize => Maximum size of each cache entry. Larger entries are not cached. # This helps prevent much of the cache being flushed when # you set an exceptionally large entry. Defaults to MaxBytes/10 # # WriteSync => 1 - DEFAULT, write() when data is dirtied for # TRUE CACHE (see below) # 0 - write() dirty data as late as possible, when leaving # cache, or when cache is being DESTROY'd # ############################################################################ # cache supports normal tied hash functions $cache{1} = 2; # STORE print "$cache{1} "; # FETCH # FIRSTKEY, NEXTKEY while(($k, $v) = each %cache) { print "$k: $v "; } delete $cache{1}; # DELETE %cache = (); # CLEAR DESCRIPTION
This module implements a least recently used (LRU) cache in memory through a tie interface. Any time data is stored in the tied hash, that key/value pair has an entry time associated with it, and as the cache fills up, those members of the cache that are the oldest are removed to make room for new entries. So, the cache only "remembers" the last written entries, up to the size of the cache. This can be especially useful if you access great amounts of data, but only access a minority of the data a majority of the time. The implementation is a hash, for quick lookups, overlaying a doubly linked list for quick insertion and deletion. On a WinNT PII 300, writes to the hash were done at a rate 3100 per second, and reads from the hash at 6300 per second. Work has been done to optimize refreshing cache entries that are frequently read from, code like $cache{entry}, which moves the entry to the end of the linked list inter- nally. INSTALLATION
Tie::Cache installs easily using the make or nmake commands as shown below. Otherwise, just copy Cache.pm to $PERLLIB/site/Tie > perl Makefile.PL > make > make test > make install * use nmake for win32 ** you can also just copy Cache.pm to $perllib/Tie BENCMARKS
There is another simpler LRU cache implementation in CPAN, Tie::Cache::LRU, which has the same basic size limiting functionality, and for this functionality, the exact same interface. Through healthy competition, Michael G Schwern got Tie::Cache::LRU mostly faster than Tie::Cache on reads & writes: Cache Size 5000 Tie::Cache 0.17 Tie::Cache::LRU 0.21 10000 Writes 1.55 CPU sec 1.10 CPU sec 40000 Reads 1.82 CPU sec 1.58 CPU sec 10000 Deletes 0.55 CPU sec 0.59 CPU sec Unless you are using TRUE CACHE or MaxBytes functionality, using Tie::Cache::LRU should be an easy replacement for Tie::Cache. TRUE CACHE
To use class as a true cache, which acts as the sole interface for some data set, subclass the real cache off Tie::Cache, with @ISA = qw( 'Tie::Cache' ) notation. Then override the read() method for behavior when there is a cache miss, and the write() method for behavior when the cache's data changes. When WriteSync is 1 or TRUE (DEFAULT), write() is called immediately when data in the cache is modified. If set to 0, data that has been modified in the cache gets written out when the entries are deleted or during the DESTROY phase of the cache object, usually at the end of a script. To have the dirty data write() periodically while WriteSync is set to 0, there is a flush() cache API call that will flush the dirty writes in this way. Just call the flush() API like: my $write_flush_count = tied(%cache)->flush(); The flush() API was added in the .17 release thanks to Rob Bloodgood. TRUE CACHE EXAMPLE
use Tie::Cache; # personalize the Tie::Cache object, by inheriting from it package My::Cache; @ISA = qw(Tie::Cache); # override the read() and write() member functions # these tell the cache what to do with a cache miss or flush sub read { my($self, $key) = @_; print "cache miss for $key, read() data "; rand() * $key; } sub write { my($self, $key, $value) = @_; print "flushing [$key, $value] from cache, write() data "; } my $cache_size = $ARGV[0] || 2; my $num_to_cache = $ARGV[1] || 4; my $Debug = $ARGV[2] || 1; tie %cache, 'My::Cache', $cache_size, {Debug => $Debug}; # load the cache with new data, each through its contents, # and then reload in reverse order. for(1..$num_to_cache) { print "read data $_: $cache{$_} " } while(my($k, $v) = each %cache) { print "each data $k: $v "; } for(my $i=$num_to_cache; $i>0; $i--) { print "read data $i: $cache{$i} "; } # flush writes now, trivial use since will happen in DESTROY() anyway tied(%cache)->flush(); # clear cache in 2 ways, write will flush out to disk %cache = (); undef %cache; NOTES
Many thanks to all those who helped me make this module a reality, including: :) Tom Hukins who provided me insight and motivation for finishing this module. :) Jamie McCarthy, for trying to make Tie::Cache be all that it can be. :) Rob Fugina who knows how to "TRULY CACHE". :) Rob Bloodgood, for the TRUE CACHE flush() API AUTHOR
Please send any questions or comments to Joshua Chamas at chamas@alumni.stanford.org COPYRIGHT
Copyright (c) 1999-2002 Joshua Chamas, Chamas Enterprises Inc. Sponsored by development on NodeWorks http://www.nodeworks.com All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.8.8 2008-03-01 Cache(3pm)
All times are GMT -4. The time now is 01:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy