It is currently Thu, 20 Jan 2022 10:31:13 GMT



 
Author Message
 extracting text
Hi All,

I'm trying to extract text from lines beginnnig with 145 (^145) from
the point beginning with $b and ahead 9 characters.

i.e.

145  randomtext$b092452569morerandomstuff
145 example$b008271451randomlengthlines

so I would want the digits 092452569 and 008271451.

A lot of the lines are the same length, so I can use cut to grab
those.  Unfortunately some aren't..

Any awk/sed/perl/shell etc. solutions welcome.

Thanks

Joe.



 Fri, 08 Sep 2006 23:15:05 GMT   
 extracting text
In article <249f8ddc.0403220715.26127...@posting.google.com>, Joe

awk '/^145/ {
    ofs = index($0,"$b");
    if (ofs != 0)
        print substr($0, ofs + 2, 9);

--
Andr Majorel <URL: http://www.**-**.com/ ~amajorel/>
Depuis Malraux, on n'a malheureu{*filter*}t jamais su trouver de
liens entre le monde intellectuel et la droite.
-- Jacques Chirac, cit dans le Canard Encha?n du 2004-02-25



 Sat, 09 Sep 2006 00:11:29 GMT   
 extracting text

Try this:

gawk '/^145/{print gensub(/(.*\$b)(.........)(.*)/, "\\2", 0)}'

Regards,

        Ed.

- Show quoted text -



 Sat, 09 Sep 2006 00:10:52 GMT   
 extracting text

a 'sed' solution can be:

sed -e '
   /^145/!d
   s/\$b[0-9]\{9\}/\
&\
/;s/.*\n..\(.*\)\n.*/\1/
' yourfile



 Sat, 09 Sep 2006 03:02:52 GMT   
 extracting text
Nell'articolo <249f8ddc.0403220715.26127...@posting.google.com>, Joe MacDonald ha scritto:

sed -e '/^145/s/^.*\$b\(.........\).*$/\1/' FILE

--
    Bye,  Daniele F.



 Sat, 09 Sep 2006 07:36:22 GMT   
 
   [ 5 post ] 

Similar Threads

1. Extracting text from a file

2. Postscript file corrupted - extracting text/patching

3. extract text from postscript

4. Question: Extracting text from a file.

5. Extracting text

6. extracting text mail messages from binary mailbox

7. extracting text between patterns

8. extracting text in bourne shell

9. Find First Match Using SED and Then Extract Text from Line

10. extract text from log file


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software