How to find n'th row from UNIX file?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to find n'th row from UNIX file?
# 1  
Old 04-29-2005
How to find n'th row from UNIX file?

Hello Gurus,

I am new to this forum and I have a BASIC knowlege in UNIX commands. I have a data file which contains 1 billion records, how to find 5678th row and put this rows into a new file? Can anybody please give the command how to do this?
# 2  
Old 04-29-2005
awk 'NR==5678{print;exit}' file1 > file2
# 3  
Old 04-29-2005
Does this mean that you have a text file with one billion lines and you want to extract line number 5678? If so, you can use sed. The normal answer would be something like:
sed -n 5678p < datafile

But I'm pretty sure that sed will read the file to the end. It will take time to read and discard those 999994322 lines. So to speed things up, use:

sed -n '5678p;5679q' < datafile
# 4  
Old 04-29-2005
or:
sed '5678q;d' datafile
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find files with 1 single row - UNIX

Hi, How could Find files with 1 single row in unix I need delete files with 1 single row (8 Replies)
Discussion started by: Marlboro
8 Replies

2. UNIX for Dummies Questions & Answers

How to find position of blank row in UNIX?

Hi I have file "emp.txt"like below Emp Id Name 123 aa 123 bb 223 cc 233 dd 334 ee Please help me to know that the position of the blank row. (5 Replies)
Discussion started by: rock_01
5 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

Read row number from 1 file and print that row of second file

Hi. How can I read row number from one file and print that corresponding record present at that row in another file. eg file1 1 3 5 7 9 file2 11111 22222 33333 44444 55555 66666 77777 88888 99999 (3 Replies)
Discussion started by: Abhiraj Singh
3 Replies

5. Shell Programming and Scripting

Replace Second row with First row in a File

Hi, I need to replace first row to second row: Input: A JACK WAS_${HH}_JACK .... Output should be: JACK WAS_A_JACK .... I tried below code.. awk '{TEMP= (NR==1)}; {sub(/${HH}/$TEMP/)}' (2 Replies)
Discussion started by: kmsekhar
2 Replies

6. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

7. Shell Programming and Scripting

Get a group of line from different file and put them into one file row by row

hi guys, today i'm stuck in a new problem. the title explain more or less but a particular had been omitted. So i'm going to describe below the situation with an example. I have different html files and each of them have a consecutive lines group inside that i want to extract. example: ... (8 Replies)
Discussion started by: sbobotex
8 Replies

8. Shell Programming and Scripting

Append Second Row to First Row @ end in a file

Hi I want to append line 2n to 2n-1 line where n=1...LastLine in my file. eg: Actual File: Hello Everyone Welcome TO Unix I need Your help Required File: HelloEveryone WelcomeTO Unix I needYour help (5 Replies)
Discussion started by: dashing201
5 Replies

9. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies

10. Shell Programming and Scripting

how to find a file in UNIX without find command?

given a start directory,a filename,how to find it? (3 Replies)
Discussion started by: bluo
3 Replies
Login or Register to Ask a Question