[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

UNIX sed command

Posted on 2011-09-15
4
Medium Priority
?
399 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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

656 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