Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi people...
How can i get a specific line of a file ?for example,,, i wanna get a third line of /etc/passwd file and then i can use awk to select a column !!

sed '3!d' /etc/passwd|awk ' BEGIN { FS=":" } { print $1 } 'but why do you need sed?
awk ' BEGIN { FS=":" } { if (NR == 3) print $1 } ' /etc/passwd

huuhhuhu thanks ... but i have other problem,,, is the same, but is other,,,
in this script for example:
#!/bin/sha=1
while [ $a -le 10 ]; do
variable=`sed '$a!d' /etc/passwd|awk ' BEGIN { FS=":" } { print $1 } '`
# or awk 'NR==$a' /etc/paswd
#
# i have to put this output to another #commands.... /etc/passwd is a example #file,,, i will use other...
#
#
#ex.: ./create add anything$variablea=`expr a + 1`
done
the problem is that the awk and sed not accept variables ...
i try use the script above,, but it not functioned

You can easily use shell variables in awk (just by adding them to the command line options) but you probably don't even need to do that: Just don't surround the variable with quotes!!!

![]() |
Hard drives start at hdc ...
|
Looping through records c...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |