Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting: How to cut character string from file ?

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

I'm trying to write a little script that's supposed to work with a certain value contained in a specific file. The File is always the same, only the value I need changes.

It looks something like that:

free space : 61.45 Percent

In order to work with that value I need to cut out the rest somehow and only write the value into a new output file.

e.g.:

I'd like to cut out

"free space : "

and

" Percent"

so that only

61.45

and is written into a new file.

How can I do this ?

Thanks in advance !

Regards,
Thomas
 
not elegant but it works :)

grep free <your_file> | tr -s ' ' ' ' | cut -f4 -d" "

to write to a new file assign it to a variable and echo the variable to the new file

VALUE=`grep free <your_file> | tr -s ' ' ' ' | cut -f4 -d" "`

echo $VALUE > new_file

Alex
 
Or just:

grep free <your_file> | tr -s ' ' ' ' | cut -f4 -d" " > new_file
 
Something like:
cat your_file |awk '{for (i=1;i<=NF;i++){if ( $i ~ /[0-9] ) {print $i}}}'
 
am i missing something? why would this not work?

awk '{print$4}' filename

IBM Certified -- AIX 4.3 Obfuscation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top