The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace a character with another character satish@123 Shell Programming and Scripting 8 05-13-2009 04:04 PM
Replace certain character with a new a new line. djsal Shell Programming and Scripting 8 01-11-2008 12:59 PM
to replace a new line character chan Shell Programming and Scripting 2 01-11-2008 12:56 PM
Replace a character in last line Mohammed Shell Programming and Scripting 6 08-01-2007 03:46 PM
How would I replace the 9th character of every line in a file? LordJezo Shell Programming and Scripting 5 09-01-2004 12:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-14-2008
borncrazy borncrazy is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 35
replace > with new line character

<reward_data><date><datetime>071308000804</datetime></date>

I want the above data to be displayed as

<reward_data>
<date>
<datetime>071308000804</datetime>
</date>

How can i accomplish this.

I tried the below

tr "><" ">\n" < filename
  #2 (permalink)  
Old 07-14-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink No one ever said it would be easy...


Code:
> cat file9
<reward_data><date><datetime>071308000804</datetime></date>

> cat file9 | sed "s/></>~</g" | tr "~" "\n"
<reward_data>
<date>
<datetime>071308000804</datetime>
</date>

I had to do a substitution to ~ to then use the tr command to get the new line. By the way, I think the tr command only works with single characters - thus your initial problem.
  #3 (permalink)  
Old 07-14-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,789
Well if you really want tr try this:

Code:
tr -s '>' '\n' < filename | sed 's/$/>/'

tr works only on single characters not "><"
  #4 (permalink)  
Old 07-14-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753

Code:
awk '{gsub("><",">\n<");print }' file

  #5 (permalink)  
Old 07-15-2008
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
Using Sed

Hi,

Try this


Code:
sed 's/></>\[press Enter(newline)]
</g' filename

Regards,
Chella
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0