The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to convert C source from 8bit chars to 16bit chars? siegfried Shell Programming and Scripting 0 09-26-2007 11:26 AM
cut last 4 chars pbsrinivas Shell Programming and Scripting 5 06-28-2007 09:14 PM
replace chars, Jairaj Shell Programming and Scripting 7 02-28-2007 03:34 AM
to append few chars at the end of a file trichyselva Shell Programming and Scripting 2 08-02-2006 04:39 AM
Awk- catching the last two chars Gerry405 UNIX for Dummies Questions & Answers 9 11-22-2005 03:23 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-17-2007
Registered User
 

Join Date: Dec 2007
Posts: 6
Using SED to get n chars after given value from file

Hello, my name is Marc, I'm a linux starter and I hope you specialists can help me solving this issue.

I have a file containing a lot of data. Somewhere in this file, there's a string called "Faultdump", directly followed by 64 chars of HEX data. I need to get the HEX part. I accomplished this with several lines of code in a script calling sed, cut as well as head/tail. I know some of you guys will manage to get this on one line by using just awk or sed by avoiding cat or head/tail. Please can anyone of you point me to the right direction?

I was searching through the forums, but I'm afraid, I couldn't find an appropriate example.

Many thanks in advance!

Marc (Kally).
Reply With Quote
Forum Sponsor
  #2  
Old 12-17-2007
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
sed -n 's/.*Faultdump\(.*\)/\1/p' filename| cut -c1-64

Should work.

Sure someone will improve on that though.

HTH
Reply With Quote
  #3  
Old 12-17-2007
Registered User
 

Join Date: Dec 2007
Posts: 6
Thanks Tytalus, I'll try it later. Looks a lot better than my commandlines.

If someone else has got another approach (using sed or awk completely alone), I'll appreciate that.

Anyway, I'm fine with Tytalus' solution, though.

Many thanks.
Reply With Quote
  #4  
Old 12-18-2007
Registered User
 

Join Date: Dec 2007
Posts: 6
I'm afraid, I tried it and it doesn't work properly, does anyone got another approach, may using AWK? I'm stuck.

Thank you very much.
Reply With Quote
  #5  
Old 12-18-2007
Registered User
 

Join Date: Nov 2007
Posts: 85
Try this one

awk '{ if(substr($0,65,9)=="Faultdump") print substr($0,1,64)}' filename
Reply With Quote
  #6  
Old 12-18-2007
Registered User
 

Join Date: Dec 2007
Posts: 6
@ranjithpr:

Thank you! I'll give you a report later then. Desi Greetings.

Marc.
Reply With Quote
  #7  
Old 12-18-2007
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
think that that awk will only work if the string faultdump starts at char 65.

so...

you could try :

grep Faultump <filename> | sed 's/.*Faultdump//' | cut -c1-64

What errors are you seeing when you try the earlier sed I gave ?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0