Computing.Net > Forums > Linux > Shell Script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shell Script

Reply to Message Icon

Name: surfistadesampa
Date: November 4, 2004 at 04:23:03 Pacific
OS: Red Hat 9
CPU/Ram: PIII
Comment:

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 !!



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 4, 2004 at 07:17:31 Pacific
Reply:


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



0

Response Number 2
Name: 3Dave
Date: November 4, 2004 at 07:36:52 Pacific
Reply:

$ awk 'NR==3' /etc/paswd


0

Response Number 3
Name: surfistadesampa
Date: November 4, 2004 at 08:25:39 Pacific
Reply:

huuhhuhu thanks ... but i have other problem,,, is the same, but is other,,,

in this script for example:
#!/bin/sh

a=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$variable

a=`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


0

Response Number 4
Name: Wolfbone
Date: November 4, 2004 at 09:29:10 Pacific
Reply:

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!!!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Shell Script

Shell Script Question www.computing.net/answers/linux/shell-script-question/15096.html

Using Mailto in shell scripts www.computing.net/answers/linux/using-mailto-in-shell-scripts/27632.html

Bourne Shell Script Problem www.computing.net/answers/linux/bourne-shell-script-problem/19777.html