Solved

UNIX sed command

Posted on 2011-09-15
4
391 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
  • 2
4 Comments
 
LVL 16

Expert Comment

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

Accepted Solution

by:
Papertrip earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
sed -e 's/|/\<\/td\>\<TD\>/g' sedtest
works for me.  thanks a lot.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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 this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now