Searching for a command...


Forum: Programming and Scripting
Topic: Searching for a command...
started by: Zucca

Posted by Zucca on July 27 2006,07:07
Is there any simple way to read a single line from a file?
Like command cat but just one line.

Example: command <line_number>

Posted by roberts on July 27 2006,15:40
Using awk...

For example to read/print the third line of the .filetool.lst file use:

awk 'NR = 3' .filetool.lst

Where NR is an internal variable of awk and is the number of records seen so far,

Posted by mikshaw on July 27 2006,19:32
For some reason that doesn't work for me.

What does work for me is grep -m3 ^ .filetool.lst|tail -1
or head -3 .filetool.lst|tail -1
sed would probably work too, but i don't know how.

Posted by roberts on July 27 2006,19:53
Make sure you use two equal signs and not one

awk 'NR == 3' .filetool.lst

Posted by Zucca on July 27 2006,20:05
Thank really much guys. This really helped me. :)

*starts to write his script*

Posted by roberts on July 27 2006,20:12
Now this one will really show my age.

ed -s .filetool.lst << EOF
3,3p
EOF

Using ed will print the third line of a line.

Does anyone still use ed ?

Posted by mikshaw on July 28 2006,03:18
Quote (roberts @ July 27 2006,15:53)
Make sure you use two equal signs and not one

awk 'NR == 3' .filetool.lst

Ah...that's the stuff.  thanks.
Posted by Zucca on July 28 2006,05:36
That command came very useful. See my automount script post.
Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.