UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 2nd, 2006, 03:17 PM
tso_2006 tso_2006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 1 tso_2006 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 29 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old May 2nd, 2006, 04:14 PM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 21
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.

Reply With Quote
  #3  
Old May 17th, 2006, 04:08 PM
kiarna kiarna is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 2 kiarna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 7 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > SED Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT