Extracting an integer from a line with the help of linux script?
I have a file, one of whose line contains:
number 8
how can i use sed, grep or whatever linux script to find out what intege开发者_如何转开发r is there in front of the line that starts with "number"?
Thanks...
awk '$1=="number"{print $2}' file
Use awk:
cat ./file.text | awk '/number/ {print $2}'
use grep and cut, this will return only the number
cat ./file.txt | grep number | cut -d " " -f 2
Another way is to use awk
:
awk '/number/ {print $2}' < ./file.txt
It's a single command, which some prefer. If it's a large file, you may prefer the cat | grep | cut
-way, as the three programs run in separate processes.
精彩评论