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
Can I create a file from the command line airon23bball Shell Programming and Scripting 5 10-21-2008 03:23 AM
find and replace command in one line using one command vasikaran UNIX for Dummies Questions & Answers 10 08-20-2008 11:40 AM
assign a command line argument and a unix command to awk variables sweta_doshi Shell Programming and Scripting 0 08-08-2008 07:54 AM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 07:06 PM
add data from command line to end of file bryan UNIX for Dummies Questions & Answers 3 05-23-2006 07:57 PM

Reply
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 06-19-2009
linux_lou linux_lou is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
File mgt: Do you know the command line command

I need a commnad to modify a file's contents from:

2009-06-18 14:14:38 CST INF Thread-114 rlo.aaf_ - MASSHANDLE: Got a valid message<Location=""><bob>2</bob><carol>61</carol><ted>54</ted><alice>1m</alice>

to this :

2009-06-18 14:14:38 CST INF Thread-114 rlo.aaf_ - MASSHANDLE: Got a valid message<Location=""><bob>2</bob>
<carol>61</carol>
<ted>54</ted>
<alice>1m</alice>

Adding the CR (\n) after each </*> and preserving the contents of each field.

Thanks for any help!
  #2 (permalink)  
Old 06-20-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

Code:
sed 's|</[^>]*>|&\
|g' "$file"
  #3 (permalink)  
Old 06-20-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,553
Code:
awk '{gsub(/<\/[^>]*>/,"\\\\&\n")}1' file
  #4 (permalink)  
Old 06-23-2009
linux_lou linux_lou is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
Thanks!

Thanks ghostdog74 & cfajohnson! Problem solved!!
  #5 (permalink)  
Old 06-24-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
Code:
my $str='2009-06-18 14:14:38 CST INF Thread-114 rlo.aaf_ - MASSHANDLE: Got a valid message<Location=""><bob>2</bob><carol>61</carol><ted>54</ted><alice>1m</alice>';
$str=~	s/(<\/[^>]*>)/$1\n/;
print $str;
Reply

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 05:47 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