The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
get all entries after particular date !! zedex Shell Programming and Scripting 7 11-23-2007 04:41 AM
separating filename and extension lucaspewkas Shell Programming and Scripting 2 04-06-2007 07:07 AM
Separating commands/programs with ; dush_19 High Level Programming 2 06-22-2006 05:34 AM
separating fields new2ss Shell Programming and Scripting 5 02-19-2006 09:02 PM
separating commands mile1982 High Level Programming 2 09-13-2004 11:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-28-2008
za_7565 za_7565 is offline
Registered User
  
 

Join Date: Nov 2007
Location: ON, Canada
Posts: 16
separating entries by using cat command

Hi there,

Is there any option if I cat the following line from a file and than redirect to another as separate entries:

unixsrv1:unixsrv2:unixsrv3:mercury:mercury01:sunprd01:sunprd02:hpprod07:ibmprod43

output to file shoudld be:
unixsrv1
unixsrv2
unixsrv3
... and so on.

Your help is really appreciated.
  #2 (permalink)  
Old 01-28-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Code:
echo 'unixsrv1:unixsrv2:unixsrv3' | tr ':' '\n'
  #3 (permalink)  
Old 01-28-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
try this:
Code:
sed 's/:/\n/g' file
  #4 (permalink)  
Old 01-28-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 414
Code:
tr ":" "\n" < file
  #5 (permalink)  
Old 01-28-2008
Karthikeyan_113 Karthikeyan_113 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Boston, USA
Posts: 16
Thumbs up Try this....

Input file:-
$ > cat 123.txt
unixsrv1:unixsrv2:unixsrv3:mercury:mercury01:sunprd01:sunprd02:hpprod07:ibmprod43
$ >

Command:-
$ > cat 123.txt | tr -s ":" "\n" > 123_1.txt
$ >

Output:-
$ > cat 123_1.txt
unixsrv1
unixsrv2
unixsrv3
mercury
mercury01
sunprd01
sunprd02
hpprod07
ibmprod43
$ >

Thanks,
Karthik.
  #6 (permalink)  
Old 01-29-2008
za_7565 za_7565 is offline
Registered User
  
 

Join Date: Nov 2007
Location: ON, Canada
Posts: 16
Excellent !! you guys are the best helpers.

A quick ?, how can I get rid of the duplicate entries: This is what I have now;
unixsrv1
unixsrv1
.
.
.
unixsrv1 (20 entries)
same for the other hosts.

I ran the following command but no luck!
# cat file | sort | uniq -d

Thanks again guys.
  #7 (permalink)  
Old 01-29-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
do not use the -d option of uniq command

edit: so this should do the job for you: cat file | sort | uniq

Last edited by Yogesh Sawant; 01-29-2008 at 07:56 AM.. Reason: added the complete command
Sponsored Links
Closed Thread

Bookmarks

Tags
sed, uniq

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 06:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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