LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 09-01-2010, 05:00 AM   #1
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Rep: Reputation: 31
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:
 
Old 09-01-2010, 05:05 AM   #2
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 248Reputation: 248Reputation: 248
Quote:
Originally Posted by genderbender View Post
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.

Last edited by xeleema; 09-01-2010 at 05:08 AM.
 
1 members found this post helpful.
Old 09-01-2010, 05:16 AM   #3
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by xeleema View Post
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 Seems to work a treat.
 
Old 09-01-2010, 05:44 AM   #4
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 248Reputation: 248Reputation: 248
Quote:
Originally Posted by genderbender View Post
That should get me going, thanks a bunch 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"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to grab one number from a row in a text but not another number Mike_V Programming 9 04-25-2009 04:57 AM
Scanning memory range for specific bytes w/ GDB jrtayloriv Programming 5 03-17-2008 02:27 PM
Monitor eth0, number of bytes passed through?? helptonewbie Linux - Networking 4 09-06-2006 10:49 AM
calling sys_read inside sys_write returns number of bytes read as zero appas Linux - Software 0 08-28-2004 07:21 AM
Calculation of number of bytes submitted with form blampain Linux - Networking 6 03-30-2004 05:54 AM


All times are GMT -5. The time now is 11:47 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration