LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   finding a string (https://www.linuxquestions.org/questions/linux-newbie-8/finding-a-string-630968/)

jkeertir 03-27-2008 05:02 AM

finding a string
 
Dear ALL,


I store the output of df command in a file named as /k.
so in /k i have this string

/dev/hdc1 24406832 666000 23740832 3% /mnt/k

now i just want to store "/mnt/k" in a variable of shell script.or in a file.i dont want to use find command.


can anyone help me to do this

With Regards,
Keerti

Nylex 03-27-2008 05:53 AM

str="/dev/hdc1 24406832 666000 23740832 3% /mnt/k"
var=`echo $str | awk '{print $6}'`

The result is in the variable $var.

jkeertir 03-28-2008 06:17 AM

Dear Nylex,

Thanks for the reply,

I could do this by the way you suggested

with Regards,
Keerti

prad77 03-28-2008 04:45 PM

var=`df | awk '{print $NF}'`

If you want to do it with a file , then

awk '{print $NF}' filename

Gentoo


All times are GMT -5. The time now is 01:47 AM.