not sure how to


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting not sure how to
# 1  
Old 06-07-2007
not sure how to

I have a command that will produce about 20 lines of output

what is the best way to store some of the results to certain variables?

let's say command output shows

--------------------------------
first 13@home
yahoo 33@never
usa 55 ussr
user logged in
--------------------------------

what is the best way to store values for first and 3rd line so that i can use it later in the script?

I started off with

somecommand | grep -v "-" | <--- but not sure how else to do it..
can i use case statement or? what can i do?


can someone please show me various ways to get this done?
# 2  
Old 06-07-2007
just one of the way
Code:
third=$(sed -n '3p' "file")
first=$(sed -n '1p' "file")

# 3  
Old 06-07-2007
I was hoping that there was way to do it without going through the whole file everytime
# 4  
Old 06-08-2007
Code:
a=$(awk 'BEGIN{li=""}NR==1||NR==3{li=$0"|"li}END{print li}' "file")
first=$(echo $a|cut -d"|" -f1)
second=$(echo $a|cut -d"|" -f2)
echo $first
echo $second

# 5  
Old 06-08-2007
Try...
Code:
eval $(awk '{printf "Row_%02d=\047%s\047\n",NR,$0}' file1)
echo $Row_01
echo $Row_03

# 6  
Old 06-08-2007
wil try them & get back to u guys.. thank u
# 7  
Old 06-08-2007
Code:
line1=1
line2=3
line_cntr=1
while read line
do
	if [ $line1 -eq $line_cntr ];then var1="$line"; fi
	if [ $line2 -eq $line_cntr ];then var2="$line"; break; fi
	line_cntr=$( expr $line_cntr + 1 )
done < filename

Login or Register to Ask a Question

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