T
T
Ten2014-08-17 20:55:15
linux
Ten, 2014-08-17 20:55:15

How to extract only what you need from output in bash?

Hello, Khabrovites.
With Linux I, alas, on "you", but sometimes tasks arise.
So, problem.
There is a command output cat /sys/bus/w1/devices/22-*/w1_slave 2>&1
in the form of two lines

9c 01 4b 46 7f ff 04 10 7a : crc=7a YES
9c 01 4b 46 7f ff 04 10 7a t=25750

I need to select what t is equal to (in this case, it is 25750).
How to implement it?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor, 2014-08-17
@Ten

cat /sys/bus/w1/devices/22-*/w1_slave 2>&1 | awk -F'=' '/t=/ {print $2}'

That is, we pass it through a pipe to awk, which processes the text line by line, where we search for t= . As a separator, we take the = sign (option -F'=' ) and display the second group of characters from the string, respectively, that is, everything after the equals sign .

S
Sergey, 2014-08-17
@bondbig

grep+sed/awk/cut to your liking.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question