Searching for data on a specific line numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching for data on a specific line numbers
# 1  
Old 06-02-2005
Searching for data on a specific line numbers

Hi,
I have a file on windows and have some unix utilitties available on windows. This file is very large and have over 5 million record. I am not able to open this file in Window Editor. I am trying to see bad data on a specific lines. I just have line numbers that has bad data. I need to see the data at that line number.
I am trying to see data let say on line 411108. I tried tail -n 411108 filename but it shows last 411108 lines instead of data on line 411108. I have tried grep and head command but it returns thousands of rows. I installed VIM on windows and tried opening the file but it only clocks for hours and does not open file. I had to kill the job.

Is there a unix command that I can use to view specific data at a certain line number. I also have sed and gawk utility available on windows.

Will appreciate any help....

Thanks
Raj
rkumar28
# 2  
Old 06-02-2005
sed -n '411108p' < datafile
will do it. However after printing the line, sed will continue to read until end of file. So this may be faster:
sed -n '411108p;411109q' < datafile
# 3  
Old 06-02-2005
Thanks a lot for a quick reply.This worked.
Just curious to know the significance of "p" and "q" in the sed command below.
sed -n 411108p;411109q < datafile

If I remove the "p" and "q" the sed errors out.

Thanks
Raj
rkumar28
# 4  
Old 06-02-2005
p=print
q=quit
# 5  
Old 06-16-2005
Problem with sed

Hi all

I have a file jh that contains :-
1
2
3
4


I use have a script as follows :-
#!/usr/bin/ksh
F1=jh
y=1
z=1

FS1=`cat $F1 | wc -l`

while [ $y -le $FS1 ]
do
set -xv
z=`expr $y + 1`
st=$y"p"
ed=$z"q"
V1=`sed -n \'$st\;$ed\' \< $F1`
echo $y
y=`expr $y + 1`
read a
done


When I execute this, I get the following result.
+ + expr 1 + 1
z=2
+ st=1p
+ ed=2q
+ + sed -n '1p;2q' < jh
sed: 0602-403 '1p;2q' is not a recognized function.
V1=
+ echo 1
1
+ + expr 1 + 1
y=2
+ read a


Can anyone tell me what is wrong ?

Thx

J
# 6  
Old 06-16-2005
You can make as,

#!/usr/bin/ksh
F1=jh
y=1
z=1

FS1=`cat $F1 | wc -l`

while [ $y -le $FS1 ]
do
set -xv
z=`expr $y + 1`
st=$y"p"
ed=$z"q"
V1=`sed -n $st\;{$ed\;} < $F1`

echo $y
y=`expr $y + 1`
read a
done
# 7  
Old 06-17-2005
You could use the tail command. But to get lines counted from the beginning of the file specify the line number with the '+' sign:
tail -n +123456789 myfile.
To get just one line pipe it to "head -1".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk, cut, to extract specific data from line

Hi guys, I have been trying to do this, but... no luck so maybe you can help me. I have a line like this: Total Handled, Received, on queue Input Mgs: 140 / 14 => 0 I need to, get the number after the / until the =, to get only 14 . Any help is greatly appreciated. Thanks, (4 Replies)
Discussion started by: ocramas
4 Replies

2. UNIX for Dummies Questions & Answers

using sed delete a line from csv file based on specific data in two separate fields

Hello, :wall: I have a 12 column csv file. I wish to delete the entire line if column 7 = hello and column 12 = goodbye. I have tried everything that I can find in all of my ref books. I know this does not work /^*,*,*,*,*,*,"hello",*,*,*,*,"goodbye"/d Any ideas? Thanks Please... (2 Replies)
Discussion started by: Chris Eagleson
2 Replies

3. Shell Programming and Scripting

Need help to replace a pattern on specific line in a data file

Hi, I want to replace specific pattern "-2.0000 2" by "1.0000 3" on a particular line (line #5) in a file 1.dat. I have about 50 more files similar to 1.dat in which I want to do this correction. Can you please suggest how can I make change only at this particular line of a file... (6 Replies)
Discussion started by: anuj06
6 Replies

4. UNIX for Dummies Questions & Answers

Get line numbers while searching the pattern in log

Hi Folks, I am searching for a pattern in logs through putty by opening the file in vi editor and reaching to the last of the file by $ and then searching the pattern , lets say I have to search the pattern abc then it would be ?abc Now I want line numbers along with the matching pattern to be... (3 Replies)
Discussion started by: SankalpS
3 Replies

5. Shell Programming and Scripting

Help with figuring division and addition based on column data and line numbers

I have a data file in the format of 1234 xxx 1234 xxx 1234 xxx 1234 xxxI want to be able to calculate the following - COLUMN1+((LINENUMBER-1)/365) The output needs to preserve the 2nd column - 1234 xxx 1234.00274 xxx 1234.00548 xxx What is the best way to do this? I am somewhat... (9 Replies)
Discussion started by: ncwxpanther
9 Replies

6. Shell Programming and Scripting

Extract character between specific line numbers

Hi guys, I have txt file and I would need to extract all the contents between specific line numbers. Line 1: apple Line 2: orange Line 3: mango Line 4: grapes Line 5: pine apple I need to extract the content between line 2 and 4, including the contents of Line 2 and 4 so the ouput... (2 Replies)
Discussion started by: gowrishankar05
2 Replies

7. Shell Programming and Scripting

Reading data from a specific line in a text file

Hello, I have a problem which is giving me headache for days, can some please help. Please see code and text fiel below. Please see text in red for the problem I am facing # Program gets an input x from user while read line ; do echo... (4 Replies)
Discussion started by: jermaine4ever
4 Replies

8. Shell Programming and Scripting

Reading data from a specific line in a text file

hello, I have got the following problem that I am hoping someone can help with please. 1. I have got the following text file (below) , the columns data are 'Test Day', 'Board', 'Betting Number'. TEXT FILE ============================================ 1 3 02-01-27-28-29-30 0 1... (1 Reply)
Discussion started by: jermaine4ever
1 Replies

9. Shell Programming and Scripting

Searching a specific line in a large file

Hey All Can any one please suggest the procedure to search a part of line in a very large file in which log entries are entered with very high speed. i have trued with grep and egrep grep 'text text text' <file-name> egrep 'text text text' <file-name> here 'text text text' is... (4 Replies)
Discussion started by: NIMISH AGARWAL
4 Replies

10. Shell Programming and Scripting

Can't figure out how to display specific data from a line using awk.

Hello, I cannot figure this one out. I would like to do the following. I have a line that has 7 words. It is possible that the line can have 20 words too. I always want to show the 9th word and beyond. The 9th word will always change so I do not have something to search for, so I think... (1 Reply)
Discussion started by: ctcuser
1 Replies
Login or Register to Ask a Question