LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Echo only text after a specific number of bytes (https://www.linuxquestions.org/questions/programming-9/echo-only-text-after-a-specific-number-of-bytes-829692/)

genderbender 09-01-2010 05:00 AM

Echo only text after a specific number of bytes
 
I've got an SNMP call which echo's the status of a tape drive, this is a string of text which will vary a great deal (e.g one time it might read "no errors" and another time it might read "tape drive x has a fault due to y we recommend you z").

I usually just do awk '{print $4}' for my snmp calls but seeing as the length is unknown, whats the best way to do this? Does awk have a 'print everything after $4' command or something? I also know the text will only appear after a set number of characters, would it be possible to print everything after 64 characters for example? I guess sed or something could (possibly) be capable of doing this.

Example below:

Code:

snmpwalk -v1 -c public 127.0.0.1 1.3.6.1.4.1.674.10893.2.102.3.1.1.24.1
SNMPv2-SMI::enterprises.674.10893.2.102.3.1.1.24.1 = STRING: "No error"

I just want whatever comes after STRING:

xeleema 09-01-2010 05:05 AM

Quote:

Originally Posted by genderbender (Post 4084587)
I also know the text will only appear after a set number of characters, would it be possible to print everything after 64 characters for example?

Quick 'N' Dirty Way
Code:

snmpwalk -v1 -c public 127.0.0.1 1.3.6.1.4.1.674.10893.2.102.3.1.1.24.1 | \
cut -b64-200

Check the man page for cut (man cut) for additional information.

genderbender 09-01-2010 05:16 AM

Quote:

Originally Posted by xeleema (Post 4084596)
Quick 'N' Dirty Way
Code:

snmpwalk -v1 -c public 127.0.0.1 1.3.6.1.4.1.674.10893.2.102.3.1.1.24.1 | \
cut -b64-200

Check the man page for cut (man cut) for additional information.

That should get me going, thanks a bunch :D Seems to work a treat.

xeleema 09-01-2010 05:44 AM

Quote:

Originally Posted by genderbender (Post 4084605)
That should get me going, thanks a bunch :D Seems to work a treat.

If you're really looking for a sed answer to your problem, then this should work:
Code:

snmpwalk -v1 -c public 127.0.0.1 1.3.6.1.4.1.674.10893.2.102.3.1.1.24.1 | \
sed -e "s/.*STRING/STRING/g"

Output should look like this;
Code:

STRING: "No error"


All times are GMT -5. The time now is 01:28 AM.