|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SED Help
I need to insert additional data into the middle of a record AND change the contents of existing data. The additional data will be using a portion of the existing data. The old record layout is something like:
hdr[5] tbl#[8] filler[5] end[10] Example of data: aaaaa12345678 zzzzzzzzzz The new layout will be: hdr[5] tbl#[8] ind[1] tbl#2[8] filler[1] end[10] Example of data: aaaaa12345678 12345678 zzzzzzzzzz Ultimately the new record will be 5 bytes bigger since the new data is using 4 bytes of the filler field. I think I can do this using the grouping argument but I'm not defining the groupings correctly. I think it should look something like: s/\(hdr data\)\(filler field\)\(end data\)/\1 12345678 \3/ Any help with the actual grouping format would be greatly appreciated. Thanks |
|
#2
|
||||
|
||||
|
Anytime you post in the UNIX forums, it's a good idea to include the OS and shell you are working with. Not all unix boxen are created equal.
Wow, you sure picked an odd example to use for sed. It's gonna be ugly, but... The grouping you've done seems to be in the correct syntax, but I can't figure why you left the second grouping out of the replacement string? Any reason? Code:
sed -e "s/\(aaaaa\)\(12345678 \)\(zzzzzzzzzz\)/\1\212345678 \3/g" That should do the trick. If you don't know what the strings are that are being replaced, it gets a bit more difficult. But the example above should help you get started. |
|
#3
|
|||
|
|||
|
more sed questions (linux)
GNU sed version 4.1.2
FC3 box. I think it's a basic owee in the brain RE problem, but my ears are starting to bleed. I'm trying to change listed images in an html file to reflect the relative path. The image names are multiple per file I only have the extension .jpg, .png, or .gif. I tried doing: sed 's|(.*\)\.png|upload\/images\/\1.png|g' filename > filename.tmp and it places the new path 'upload/images/' at the beginning of the line rather than appending it to the image name. any suggestions for what I'm maiming with my RE? Thank ya! XK |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > SED Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|