Sort a file from specific row onwards


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort a file from specific row onwards
# 1  
Old 05-13-2011
Sort a file from specific row onwards

Hello All:

I've file in below format. File name is "FIRSTN.TBL":

AAAAAA N
BBBBBBBBBBBBBBBBBBBBBBB N
.
.
.
.
ZZZZZZZZZZZZZZZZZZZZZZZZZZ N

My file row length is 40 characters and my second column will start from 25th column and it is only one letter. My file having 20177 total records.

I want to sort from 500th row to end of file. Can anyone advice me how to sort FIRSTN.TBL from 500th row to end of file.

Thanks for your help in advance.
PS: I am using "SuSE Linux Enterprise Server 9" platform

- Eswar
# 2  
Old 05-13-2011
first extract the rows from 500 to last in a temp file. sort that file , then concat with the first 500 rows of original file.

Code:
head -n500 FIRSTN.TBL >temp.txt
head -n-500 FIRSTN.TBL |sort >>temp.txt

temp.txt will have the result.
# 3  
Old 05-13-2011
Sort a file from specific row onwards

Kumaran:

Thanks for your reply. My requirement is to sort a file FROM 500TH row onwards to END OF FILE but NOT first 500 lines.
# 4  
Old 05-13-2011
the first line will extract the first 500 lines into a new file without any sort. this is optional if you require this 500 lines to be present in the output.

The second command will extract lines from 500 till last and sort and will append the result in the previous file.

this will only take lines starting from 501 and do the sort.
Code:
head -n-500 FIRSTN.TBL|sort >result.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to change a specific column and in a specific row

I am trying to change the number in bold to 2400 01,000300032,193631306,190619,0640,1,80,,2/ 02,193631306,000300032,1,190618,0640,CAD,2/ I'm not sure if sed or awk is the answer. I was going to use sed and do a character count up to that point, but that column directly before 0640 might... (8 Replies)
Discussion started by: juggernautjoee
8 Replies

2. Shell Programming and Scripting

Sort by first row - awk

how can i sort the table based on first row? thanks in advance input name d b c a l l1 l2 l3 l4 l1 1 2 3 4 l2 2 2 2 1 l3 1 1 2 2ouput name a b c d l1 l4 ... (4 Replies)
Discussion started by: quincyjones
4 Replies

3. Shell Programming and Scripting

Search row by row from one file to another file if match is found print few colums of file 2

this is the requirement list.txt table1 table2 table3 testfile.txt name#place#data#select * from table1 name2#place2#data2#select * from table 10 innerjoin table3 name2#place2#data2#select * from table 10 output name place table1 name2 place table3 i tried using awk (7 Replies)
Discussion started by: vamsekumar
7 Replies

4. Shell Programming and Scripting

Grepping a specific row from a file

Hi I have output of a command saved in a file.. # cat /file.txt System: cu=4 ent=0.1 mode=on cu min u s w i 0 500 0.1 0.3 0.5 0.1 1 200 0.5 0.2 0.3 0.0 By using ksh, what I need to do is, I need to grep the u,s,w and i... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

5. Shell Programming and Scripting

Need to check a file from a certain position and date onwards

Hi Guys, I need some advice please. My script is not grabbing information from a text file from a certain date correctly. It seems to be grabbing everying in the file, i know it is something simple but i have looked to hard and to long, to know what the issue is. Script awk '... (9 Replies)
Discussion started by: Junes
9 Replies

6. Shell Programming and Scripting

Sort each row (horizontally) in AWK or any

Hello, How to sort each row in a document with numerical values and with more than one row. Example Input data (file1.txt): 4 6 8 1 7 2 12 9 6 10 6 1 14 5 7 and I want the the output to look like this(file2.txt): 1 4 6 7 8 2 6 9 10 12 1 5 6 7 14 I've tried sort -n file1.txt >... (12 Replies)
Discussion started by: joseamck
12 Replies

7. Shell Programming and Scripting

Sort data from column to row

Hi, I need somebody's help with sorting data with awk. I've got a file: 10 aaa 4584 12 bbb 6138 20 ccc 4417 21 ddd 7796 10 eee 7484 12 fff ... (5 Replies)
Discussion started by: killerbee
5 Replies

8. Shell Programming and Scripting

Need to check a file from a certain position onwards

Scripting Guru's, I need your help, can you tell me how i can check a file from a certain point onwards via a ksh script. Currerntly i am checking the whole file and can't script it so it checks from 17.01.2012 20:00:00 onwards please.. Any help will be greatly appericated. See file... (10 Replies)
Discussion started by: Junes
10 Replies

9. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

10. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies
Login or Register to Ask a Question