Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I see one line in a file 1

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I have a standard text file of 100 000 lines.
I want to edit line 65800.
I can do this with "sed" but then how do I view just that line to check my changes ?
 
Unlikely, I know but if the changes you are making result in the line containing a string unique to the rest of the file, just do a grep on the string in question. Does this help?
 
Try the following:

cat file1 | grep -n "." | grep "65800:"

This greps file1 displaying every line number ,then it greps the result by the linenumber with a column separator.

Hope it helps "Long live king Moshiach !"
 
Oops...

Actualy:

cat file1 | grep -n "**" | grep "65800:"

This way you grep ALL lines in the file1.
"Long live king Moshiach !"
 
The lines aren't numbered,what creates the line number is "grep -n" statement.
The final best version is:

cat file1 | grep -n "**" | grep "^65800:"

This will grep only the line starting with the requested line number.
"Long live king Moshiach !"
 
If I try this using line 3, I get multiple output line (which is not correct. I only want to show my specific line)
 
Tison,

cat file1 | grep -n "**" | grep "^65800:"

^65800: should show ONLY the lines STARTING with your line number. "Long live king Moshiach !"
 
Try
[tt]
awk 'NR=65800 {print}' /your/file/here
[/tt]

I hope it works...
Unix was made by and for smart people.
 
Is there a problem with the following?

head -65800 file1 | tail -1 Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
I only think starting only one process is faster.
I hope it works...
Unix was made by and for smart people.
 
Is there a faster and better way to update a record in a file (without used sed) ?
 
I suggest awk, and I recommend the O'Reilly book on sed and awk.
 
I looked up some stuff. If you want to look at line 3 in file:

#awk ' NR == 3 { print $0 } ' file

Still not sure what could possibly be faster than sed, though.
 
I tried the awk method but it is too slow.
The head | tail method is faster.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top