please help sirs/madams


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers please help sirs/madams
# 1  
Old 09-27-2008
please help sirs/madams

shell script that accepts a file name starting and ending line numbers as arguments and displays all the lines between the given line numbers

i got it with awk but i need it with a shell script please.......

$ awk ‘NR>2&&NR<5 {print NR,$0}' lines.dat

I/P: line1
line2
line3
line4
line5

O/P:
line3
line4

# 2  
Old 09-27-2008
please help me sirs/madams

a shell script that takes a login name as command -line argument and reports when that person logs in

i got it with the awk as shown in below but i need it with shell .

$w>file1
$awk -F" " '/loginname/{print $4}' file1



please send me the shell script program
# 3  
Old 09-27-2008
please help

please send me how to do"shell script that determines the period for which a specified user is working on the system" i am unable to do it
# 4  
Old 09-27-2008
Quote:
Originally Posted by sankar_1209
a shell script that takes a login name as command -line argument and reports when that person logs in

i got it with the awk as shown in below but i need it with shell .

$w>file1
$awk -F" " '/loginname/{print $4}' file1



please send me the shell script program

Here's a simple shell script that will generate the same output that
your awk command would produce:

#!/bin/bash
echo "Login time for $1:"
w | grep $1 | awk '{print $4}'


Save that text to a file, eg who.sh, then set executable eg
$ chmod +x who.sh

Then run the script and give it the login name you're looking for eg:
$ ./who.sh myuser
# 5  
Old 09-27-2008
Quote:
Originally Posted by sankar_1209
shell script that accepts a file name starting and ending line numbers as arguments and displays all the lines between the given line numbers

i got it with awk but i need it with a shell script please.......

$ awk ‘NR>2&&NR<5 {print NR,$0}' lines.dat

I/P: line1
line2
line3
line4
line5

O/P:
line3
line4

Here's your awk command included in a bash script

#!/bin/bash
echo "Printing from line $1 to line $2"
awk "NR>$1&&NR<$2 {print \$0}" $3
# 6  
Old 09-28-2008
Lightbulb Would this sed line work?

Asuming $1 is your file name, $2 from line, $3 to line...

sed "/${2},${3}/p" ${3} > resultfile
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question