Results 1 to 3 of 3
Hello, I have a bash script that runs two programs.
I take the output of the first program, and re-direct it to an ouput file:
Code:
ns net.tcl $currentCAC > ...
- 06-25-2007 #1Just Joined!
- Join Date
- Feb 2007
- Location
- Winnipeg, MB
- Posts
- 14
Bash script manipulate output
Hello, I have a bash script that runs two programs.
I take the output of the first program, and re-direct it to an ouput file:
Then I do a grep on the output file to get the relevant info:Code:ns net.tcl $currentCAC > output
This outputs a line to the console:Code:grep KEYWORD output
I want to get the '90' part of that line, and store it in a bash variable. How can I do this?KEYWORD So that's a buffering time of 90.9121 ms
- 06-26-2007 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
assuming that the line where KEYWORD is found is always the same number of fields. The only changing part is the '90' part which is field 8
Code:awk '/KEYWORD/{print $8 }' output
- 06-26-2007 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Modern versions of grep can do this kind of extraction:
producing:Code:#!/bin/sh # @(#) s1 Demonstrate grep selection of only the matching text. set -o nounset echo " sh version: $BASH_VERSION" echo " KEYWORD So that's a buffering time of 90.9121 ms" | egrep -o '[0-9.]+' exit 0
cheers, drlCode:% ./s1 sh version: 2.05b.0(1)-release 90.9121
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote