Solved

UNIX sed command

Posted on 2011-09-15
4
397 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 125 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…

705 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