Sorting the records in the Flat file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting the records in the Flat file
# 1  
Old 01-05-2009
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  
Old 01-05-2009
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  
Old 01-05-2009
You can use only 'sort tmp.txt'. It should work fine.
# 4  
Old 01-06-2009
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  
Old 01-06-2009
Code:
head -1 file >tmp.txt&&sed '1d' file|sort -d -u -k1 >>tmp.txt

# 6  
Old 01-06-2009
Or simply with awk:

Code:
awk '{print $NF|"sort"}' file

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting a file of book records

I have a texinfo file containing book records and I want to sort them. An example is shown below. Records are separated by two blank lines. The sort pattern I want to sort is starting from the beginning of the year declaration and finishing at the beginning of the book title where I use the... (4 Replies)
Discussion started by: Danette
4 Replies

2. Shell Programming and Scripting

Sorting group of records and loading last record

Hi Everyone, I have below record set. File is fixed widht file 101newjersyus 20150110 101nboston us 20150103 102boston us 20140106 102boston us 20140103 I need to group record based on first 3 letters in our case(101 and 102) and sort last 8 digit in ascending order and print only... (4 Replies)
Discussion started by: patricjemmy6
4 Replies

3. Shell Programming and Scripting

Remove somewhat Duplicate records from a flat file

I have a flat file that contains records similar to the following two lines; 1984/11/08 7 700000 123456789 2 1984/11/08 1941/05/19 7 700000 123456789 2 The 123456789 2 represents an account number, this is how I identify the duplicate record. The ### signs represent... (4 Replies)
Discussion started by: jolney
4 Replies

4. Shell Programming and Scripting

Sorting the records for a file

hi, Please suggest me how to do this logic say i am dynamically taking a file name into the script. when ever a file name it should sort the all the records based on the first character in every line except the heading line and ending line. for example file1 heading... (1 Reply)
Discussion started by: angel12345
1 Replies

5. Shell Programming and Scripting

How do I load records from table to a flat file!

Hi All, I need to load records from oracle table XYZ to a flat file say ABC.dat. could any one tell me how do i do this in UNXI, Regards Ann (1 Reply)
Discussion started by: Haque123
1 Replies

6. UNIX for Dummies Questions & Answers

Conditional sorting on fixed length flat file

I have a fixed length file that need to be sorted according to the following rule IF B=1 ORDER by A,B Else ORDER by A,C Input file is ABC 131 112 122 231 212 222 Output needed ABC 112 131 122 212 231 222 (1 Reply)
Discussion started by: zsk_00
1 Replies

7. Shell Programming and Scripting

How to delimit a flat file with records with SED

Hi gurus, hoping someone can help with a sed line that can do the following... I have a flat file with about 1000 records, but in order to import into openoffice spreadsheet, I need to create a delimited file. I'd like to do 2 things with the SED command: 1- add a pipe character "|" at the end... (4 Replies)
Discussion started by: RogCor
4 Replies

8. UNIX for Advanced & Expert Users

Records mismatch while sorting in MPRAS and SunOS

Hi, As part of migrating a script from SunOS to MP RAS, the following script is not functioning in desired way. sort -t\| -u +6 -7 +12 -14 textfile1.out > \ textfile2uniq.out The -u is fetching unique records differently on SunOS and MP RAS Pentium IV. And thus the records... (1 Reply)
Discussion started by: RRVARMA
1 Replies

9. Shell Programming and Scripting

Inserting records from flat file to db table

I have 20000 numbers present in a file in each line like 25663, 65465, 74579, 56446, .. .. I have created a table in db with single number column in it. create table testhari (no number(9)); I want to insert all these numbers into that table. how can i do it? can anybody please... (4 Replies)
Discussion started by: Hara
4 Replies

10. Shell Programming and Scripting

Sorting a flat file based on multiple colums(using character position)

Hi, I have an urgent task here. I am required to sort a flat file based on multiple columns which are based on the character position in that line. I am restricted to use the character position instead of the space and sort +1 +2 etc to do the sorting. I understand that there is a previous... (8 Replies)
Discussion started by: cucubird
8 Replies
Login or Register to Ask a Question