Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-17-2009, 08:09 AM   #1
LQ Newbie
Registered: Aug 2008
Posts: 7

Rep: Reputation: 0
Red face using sed for transformation text


I'm a sed newbie and need this:

DBMS_OUTPUT.PUT_LINE("text " ||table1|| " moretext: " ||table2||);

To be converted in something like this:

RAISE DEBUG "text % moretext: %";

(^^The two '%' signs represent table1 & table2).

So, I need to replace all values on that line surrounded by || in % signs, and all other text ( 'moretext:' ) just needs to be put in the string, in the right place.

I find it really hard to find the right syntax for this sed command, so if someone could give me some hints I would be really happy

Greetz Daan

ps: please consider that there could be more than 2 extra fields, and more textfields.
Old 04-17-2009, 01:48 PM   #2
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
I'm not sure that sed is flexible enough for what you want. I'm fairly certain that awk would be, but I only use it for fairly simple things, so I wouldn't be able to help there. My weapon of choice for this sort of thing would be Perl.

Assuming the simple structure you show here, where the string is effectively delimited by double-quotes, and the text fields and tables alternate, this simple little script would work:

$str2mung = $ARGV[0];

$munged_str = "RAISE DEBUG \"";

(@mungarray) = split('"',$str2mung);

for ($i = 1; $i <= $#mungarray; $i += 2) {
   $munged_str .= "$mungarray[$i]%";

print "$munged_str\";\n";
It would take the input string as a command line argument (protected by single-quotes):
rob:perl$ ./ 'DBMS_OUTPUT.PUT_LINE("text " ||table1|| " moretext: " ||table2||)'
RAISE DEBUG "text % moretext: %";
If you need to do something more complex, then Perl is definitely the beast for you - Beginning Perl


Last edited by Robhogg; 04-17-2009 at 02:15 PM. Reason: Added link to Beginning Perl
Old 04-17-2009, 01:54 PM   #3
Registered: Feb 2003
Posts: 482

Rep: Reputation: 33
here's some reference for you.


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
using sed to replace text on one line in a text file vo1pwf Linux - Newbie 5 06-24-2009 07:54 AM
LXer: Simple Text Transformation Tool LXer Syndicated Linux News 0 05-08-2008 06:20 AM
sed: delete text till <pattern2> depending on length of text oyarsamoh Programming 2 05-05-2007 01:40 AM
Text transformation Sabinou Linux - General 6 04-15-2007 12:01 PM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 04:32 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:14 PM.

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