Help Please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Please
# 1  
Old 10-20-2008
Help Please

I have a file that with 15 lines and i have to display the 5th and 8th records

i tried using the cut -f5,8 filename but its display blank lines
i thought maybe i have to use the head and tails optin but not sure how to use that.....
can some one give me a hint please
thank you
# 2  
Old 10-20-2008
Give this a try...

=========================================
#!/usr/bin/ksh
x=0
while read line
do
x=`expr $x+1`
if [[ $x -eq 5 ]] || [[ $x -eq 8 ]]
then
echo "$line"
fi
done < file.txt
=========================================
where file.txt is the name of your file...

Seth
# 3  
Old 10-20-2008
thank you so very much but we did not learn those things yet
# 4  
Old 10-20-2008
You can also do this on the command line... it is ugly but it works...

to get the 5th line do
$ head -5 file.txt | tail -1

and to get the 8th line do
$ head -8 file.txt | tail -1
# 5  
Old 10-20-2008
thank you anyother options or is that the only one
i am just trying to see all possible ways
Login or Register to Ask a Question

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