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
replacing characters infyanurag Shell Programming and Scripting 3 05-21-2008 02:55 AM
Replacing characters in csv file finwhiz UNIX for Dummies Questions & Answers 1 03-31-2008 06:25 AM
replacing characters palmer18 UNIX for Dummies Questions & Answers 3 08-20-2007 10:58 AM
Replacing characters in file with line break johnemb Shell Programming and Scripting 10 04-26-2007 08:38 AM
Replacing all but last Hex characters in a text line BAH Shell Programming and Scripting 2 03-26-2004 04:00 AM

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 05-13-2007
Bashar Bashar is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 66
replacing certain characters with new line?

i have a text file which domains something like this

123213213213/32434342
324324324/12312321321
12321321,435435435
12321312 / 12313213 / 12435435345
4353213 , 123213213213
21321321312-12334324
234324324 - 235645645645
456456456 - 45456456456 - 45645645654243

how can i replace '/' and ' / ' and ',' and '-' and ' - ' with new line so the numbers gets sorted all into new lines using any tool such as sed, awk etc.. ?


Thank you.
  #2 (permalink)  
Old 05-13-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,428
Try :
awk '{gsub(/ - |-| \/ |\//, "\n"); print' infile > outfile
-->
Code:
awk '{gsub(/ - |-| \/ |\//, "\n"); print' infile > outfile
        

Jean-Pierre.
  #3 (permalink)  
Old 05-13-2007
Bashar Bashar is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 66
Quote:
Originally Posted by aigles
Try :
awk '{gsub(/ - |-| \/ |\//, "\n"); print' infile > outfile
-->
Code:
awk '{gsub(/ - |-| \/ |\//, "\n"); print' infile > outfile
        

Jean-Pierre.
i corrected itto awk '{gsub(/ - |-| \/ |\//, "\n"); print}'
-->
Code:
awk '{gsub(/ - |-| \/ |\//, "\n"); print}'
        
but it didnt replace , with new lines any idea why? although it did work just fine for the dashes and slashes


Thanks
  #4 (permalink)  
Old 05-13-2007
Bashar Bashar is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 66
never mind this did it awk '{gsub(/ - |,|-| \/ |\//, "\n"); print}' in > out
-->
Code:
awk '{gsub(/ - |,|-| \/ |\//, "\n"); print}' in > out
        


Thanks again
  #5 (permalink)  
Old 05-13-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,914
With GNU Awk:

awk '$1=$1' RS="[\n/,-]" inputfile
-->
Code:
awk '$1=$1' RS="[\n/,-]" inputfile
        
Otherwise:

sed 's/ *[/,-] */\ /g' inputfile -->
Code:
sed 's/ *[/,-] */\
/g' inputfile
        
Then use sort to order the output.
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 07:26 AM.


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