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
How to delimit a flat file with records with SED RogCor Shell Programming and Scripting 4 10-28-2008 01:18 PM
Records mismatch while sorting in MPRAS and SunOS RRVARMA UNIX for Advanced & Expert Users 1 07-02-2008 08:18 AM
Count No of Records in File without counting Header and Trailer Records guiguy Shell Programming and Scripting 2 06-07-2007 12:15 PM
Inserting records from flat file to db table Hara Shell Programming and Scripting 4 12-27-2006 03:35 AM
Sorting a flat file based on multiple colums(using character position) cucubird Shell Programming and Scripting 8 07-25-2006 12:47 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-05-2009
sudhir_barker sudhir_barker is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 2
Sorting the records in the Flat file

Hi all,

I am using this command "sort -d -u -k1 IMSTEST.74E -o tmp.txt" to the records in the flat.

Can any tell me how to sort the file except first line in the file

For ex:
i/p
First line: DXYZ
Second line : jumy
third : cmhk
fourth : andy

Output should be:
DXYZ
andy
cmhk
jumy


Thanks In Advance
Sudhir
  #2 (permalink)  
Old 01-05-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,788
Code:
head -n 1 IMSTEST.74E > tmp.txt
tail -n +2 IMSTEST.74E > main.txt
sort -d -u -k1 main.txt >> tmp.txt
rm main.txt
  #3 (permalink)  
Old 01-05-2009
ssachins ssachins is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 29
You can use only 'sort tmp.txt'. It should work fine.
  #4 (permalink)  
Old 01-06-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,047
Code:
#! /usr/bin/perl
open FH,"<a.txt";
while(<FH>){
	chomp;
	my @tmp=split(":",$_);
	push @arr,$tmp[1]."\n";
}
print $arr[0],sort @arr[1..$#arr];
  #5 (permalink)  
Old 01-06-2009
frostmourn frostmourn is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 8
Code:
head -1 file >tmp.txt&&sed '1d' file|sort -d -u -k1 >>tmp.txt
  #6 (permalink)  
Old 01-06-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Or simply with awk:

Code:
awk '{print $NF|"sort"}' file
Regards
Sponsored Links
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 11:46 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