?
Solved

UNIX sed command

Posted on 2011-09-15
4
Medium Priority
?
398 Views
Last Modified: 2012-05-12
I need to replace a line using sed command.
Original line:
Job|Data Load14-SEP-11|14-SEP-11|Completed|

I'd like to get the result as this:
Job</td><TD>Data Load</td><TD>14-SEP-11</td><TD>14-SEP-11</td><TD>Completed</TD>

I did:  sed -e 's/|/"</td><TD>"/g' sql.log
but I got the error of "sed: command garbled"

Please advise.  thanks.

0
Comment
Question by:scpig
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:medvedd
ID: 36544291
sed -e 's?|?"</td><TD>"?g' sql.log
0
 
LVL 21

Accepted Solution

by:
Papertrip earned 500 total points
ID: 36544299
So your original line, desired results, and example sed testing don't totally match up.

First let's just fix your sed syntax:

user@box:~$ cat sedtest
Job|Data Load14-SEP-11|14-SEP-11|Completed|
user@box:~$ sed -e 's/|/\<\/td\>\<TD\>/g' sedtest
Job</td><TD>Data Load14-SEP-11</td><TD>14-SEP-11</td><TD>Completed</td><TD>

Open in new window


That however doesn't match your desired results -- you need "Data Load14-SEP-11" separated as well even though there is no pipe between Data Load and 14-SEP-11?  Also, in your desired results, you only have <TD> at the end, but as you can see it's going to add the full "</td><TD>" since it's replacing "|"

Can you confirm if the example I pasted is what you want?  Not sure if it was some typo's in your example or not.
0
 

Author Comment

by:scpig
ID: 36544495
yes sorry I had typo in the original line.  it should be

Job|Data Load|14-SEP-11|14-SEP-11|Completed|

The way that the author Papertrip told me works right for me.

sed -e 's/|/\<\/td\>\<TD\>/g' sedtest
 
thanks a lot.



0
 

Author Closing Comment

by:scpig
ID: 36544499
sed -e 's/|/\<\/td\>\<TD\>/g' sedtest
works for me.  thanks a lot.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question