![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Using SED to get n chars after given value from file
Hello, my name is Marc, I'm a linux starter
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). |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
sed -n 's/.*Faultdump\(.*\)/\1/p' filename| cut -c1-64
Should work. Sure someone will improve on that though. HTH |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
Try this one
awk '{ if(substr($0,65,9)=="Faultdump") print substr($0,1,64)}' filename
|
|
#6
|
|||
|
|||
|
@ranjithpr:
Thank you! I'll give you a report later then. Desi Greetings. Marc. |
|
#7
|
||||
|
||||
|
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 ? |
||||
| Google The UNIX and Linux Forums |