grep filter within line?
after using grep, I have the following line:
Code:
:Temperature 49 thanks. |
You can either pipe the output to another grep to match exactly the number at the end of the line and using the -o option to print out only the matching part:
Code:
grep Temperature file | grep -E -o [0-9]+$ Code:
awk '/:Temperature/{print $NF}' file |
Or use sed:
Code:
sed 's/^:Temperature \([0-9]\+\)$/\1/' |
You can also use 'cut' command:
$ echo ":temperature 49" | cut -d" " -f2 49 |
thanks all.
er, there are actually two lines with :Temperature, and I'd like to merge both numbers into one line. is there a way to combine these two awk into single awk: Code:
awk '/:Temperature/{print $2}' | awk '{ printf "%s ", $0 }' or some better way? |
Quote:
|
nevermind, I just found out how to do it:
awk '/:Temperature/{printf "%s ", $2}' the two lines are these: :Temperature 48 :Temperature 25 and output should be: 48 25 thanks. |
That's it. You may want to add a terminating newline:
Code:
awk '/:Temperature/{printf "%d ", $NF} END{printf "\n"}' file |
All times are GMT -5. The time now is 10:32 AM. |