Solved

UNIX sed command

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
problem with for loop, looping forever, not exiting 5 56
PowerShell Get-Help 10 68
incorrect file reading in bash 7 78
how to pick only current date files from a ftp 14 53
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 …
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

930 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

13 Experts available now in Live!

Get 1:1 Help Now