The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
creating a new profile from command line cleansing_flame OS X (Apple) 2 12-03-2007 05:57 PM
making sure a command line paramter is a number rcunn87 Shell Programming and Scripting 3 07-13-2006 07:36 AM
Creating a line for printing jhansrod Shell Programming and Scripting 3 06-17-2005 02:38 AM
Making multi line output appear on one line djsal Shell Programming and Scripting 1 10-07-2004 03:21 PM
Making Emacs to show line number saurya_s UNIX for Dummies Questions & Answers 9 01-28-2004 09:32 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-28-2008
Registered User
 

Join Date: Mar 2008
Posts: 5
Stumble this Post!
creating conditions for making a new line?

Basically I want to change this:

a:b
c:d:e
f:g
h:i:j
k:l

into

a:b
c
d:e
f:g
h
i:j
k:l

so like if there is two :'s in one line making the first into a new line. If anyone knows how to do this I would be very appreciative!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-28-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 951
Stumble this Post!
Code:
awk  'BEGIN { FS=":"; OFS=":" }
NF == 3 { printf "%s\n%s:%s\n", $1, $2, $3 }
NF != 3 { print }
' myfile
Reply With Quote
  #3 (permalink)  
Old 03-28-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,536
Stumble this Post!
Code:
awk 'NF==3?sub(/:/,RS):1' FS=: file
Use awk or /usr/xpg4/bin/awk on Solaris.

or:

Code:
sed '/:.*:/{s/:/\
/;}' file
Reply With Quote
  #4 (permalink)  
Old 03-28-2008
Registered User
 

Join Date: Mar 2008
Posts: 5
Stumble this Post!
[quote=radoulov;302179620]
Code:
awk 'NF==3?sub(/:/,RS):1' FS=: file
Use awk or /usr/xpg4/bin/awk on Solaris.

This is kind of working but it is sometimes deleting the second field rather than just creating a new line.
Reply With Quote
  #5 (permalink)  
Old 03-28-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,536
Stumble this Post!
Could you please post the input that causes this behaviour?

Thank you!
Reply With Quote
  #6 (permalink)  
Old 03-28-2008
Registered User
 

Join Date: Mar 2008
Posts: 5
Stumble this Post!
Code:
sed '/:.*:/{s/:/\
/;}' file
[/quote]

I am using Putty and it wont perform this command. It is returning this reply:

-bash-2.05b$ sed '/:.*:/{s/:/\/;}' ./assignment1/question3/a.txt
sed: -e expression #1, char 15: Unterminated `s' command

Do you know why? Am I typing the command wrong?
Reply With Quote
  #7 (permalink)  
Old 03-28-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,536
Stumble this Post!
Quote:
Originally Posted by Audra View Post

I am using Putty and it wont perform this command. It is returning this reply:

-bash-2.05b$ sed '/:.*:/{s/:/\/;}' ./assignment1/question3/a.txt
sed: -e expression #1, char 15: Unterminated `s' command

Do you know why? Am I typing the command wrong?
Yes ther's a new line after the \ character:
Is this a homework?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
solaris

Thread Tools
Display Modes




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0