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
Sorting a file mtechnocrat UNIX for Dummies Questions & Answers 11 06-28-2007 07:28 AM
need help with sorting a file pieman8080 Shell Programming and Scripting 5 11-21-2006 01:50 PM
Sorting a file Khoomfire Shell Programming and Scripting 2 12-13-2005 07:48 AM
sorting file sx3v1l_1n51de Shell Programming and Scripting 4 06-22-2005 01:16 PM
Help sorting file. gio123bg Shell Programming and Scripting 3 12-10-2003 10:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-25-2006
phani_sree phani_sree is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 52
file sorting

i have a data in afile like this
**************************************
sree
sree@yahoo.com
98662323432
*************************************
phani
phani@yahoo.com
98662323344
*************************************
i want to sort the file with respect to name.
how can i do this.
thank u,inadvance
  #2 (permalink)  
Old 11-25-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
something here

Code:
paste -s -d "\t\t\t\n" filename|sort -d -k2,2|tr "\t" "\n"
You could try modifying to get the required output.

Regards
  #3 (permalink)  
Old 11-25-2006
ramesh.jella ramesh.jella is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 22
thank you

hi
paste -s -d "\t\t\t\n" filename|sort -d -k2,2|tr "\t" "\n"

sorry to tell this, i unable to understand this code.
actually i am sorting the file in alphabetical order.
will u please send me some detailed code or an example.

thank you

ramesh
  #4 (permalink)  
Old 11-25-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
hi

What i tried was to join the 4 lines(which form a group) into a single line and then sort bsed on the required key and then get back the old format.
Input data -
Quote:
**************************************
sree
sree@yahoo.com
98662323432
*************************************
phani
phani@yahoo.com
98662323344
*************************************
Code:
1) paste -s -d "\t\t\t\n" filename gives
xrkrb@chu10t1: /home/xrkrb/unix_forum>paste -s -d "\t\t\t\n" mytestfile
**************************************  sree    sree@yahoo.com  98662323432
*************************************   phani   phani@yahoo.com 98662323344
*************************************
2) then you sort the lines based on the second field which is the name 
3) get back the original format as it existed in the original file - this is done by 'tr'

Last edited by ranj@chn; 11-25-2006 at 08:51 AM.. Reason: typo errors
  #5 (permalink)  
Old 02-03-2007
phani_sree phani_sree is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 52
thank u

but it's showing on the terminal
but in file sorting is not happening
how we can apply this this our file
  #6 (permalink)  
Old 02-05-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by phani_sree
but it's showing on the terminal
but in file sorting is not happening
how we can apply this this our file
Code:
paste -s -d "\t\t\t\n" filename|sort -d -k2,2|tr "\t" "\n" > tmp
mv tmp filename
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 05:33 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