Find the answer to your Linux question:
Results 1 to 3 of 3
I have a problem where I need to examine files like the one below. I need to find the text "GCH:GCH" and return the next 2 characters, in this case ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2011
    Posts
    2

    Bash problem, returning data from a file


    I have a problem where I need to examine files like the one below. I need to find the text "GCH:GCH" and return the next 2 characters, in this case I need to return "L1" ("GCHL1" would be fine also). Any idea how I can do this in bash?
    Any help would be appreciated.
    Thanks,
    Tim J.

    *******************************
    ^FO 65,126,^AD ^FDURCUL ^FS
    ^FO 65,143,^AD ^FD^FS
    ^FO355,154,^A0,25,25 ^FD^FS
    ^FO345,161, ^GB80,30^FS
    ^FO100,160,^AF ^FDJ815^FS
    ^FO165,160,^A0,30,30 ^FD0026^FS
    ^FX under Peel Line ^FS
    ^LH0,0^FS
    ^FO430, 76,^A0R,30,25 ^FDGCH:GCHL1^FS
    ^FO25,60,^ADR ^FDSTAFF M,M^FS
    ^LH0,0^FS
    ^XZ
    ************************************

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,345
    Code:
    sed -n 's/\(.*\)GCH:GCH\(..\)\(.*\)/\2/p' <TEXTFILE>
    I tried to write that regex greedy, but it seems it's already too late this day
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Jun 2011
    Posts
    2
    Thank you! That's perfect.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •