The output of command line utility ./Utility -P
consist of two rows of text.
I use shell script to capture standard output from this sub shell and show it as notification use zenity
:
#!/bin/bash
output="$( ./Utility -P )"
zenity --info --text "${output}" --title "Job done"
The only the second row matters, so I need show only 2nd row from the utility output. Now I can pipe only 2nd row for further processing in above shell script?
I'm considering use awk
sample:
awk -F: 'NR==2 {print $1}' filename
How to connect this sample to above shell code?
awk -F: 'NR==2 {print $1}' filename
? If you want the whole second line,awk 'NR==2 {print}' filename
=>output=$(./Utility -P | awk 'NR==2 {print}')
, however for this task you could use justsed
:output=$(./Utility -P | sed -n '2p')
output="$( ./Utility -P | awk 'NR==2 {print}')"
var=something
: unix.stackexchange.com/a/599170/114435sed
:output=$(./Utility -P | sed -En '2s/.*?(.{10})$/\1/p')
(this will remove everything but the last 10 characters on line 2, regardless of the characters, I think it's ok? Otherwise if you want to avoid printing in case one of the last ten characters is something other than a letter or a digit:output=$(./Utility -P | sed -En '2s/.*?([A-Za-z0-9]{10})$/\1/p')
)Utility
thing? Is it printing using Windows-style line-endings (\r\n
)? Try./Utility -P | tr -d '\r' | sed -En '2s/.*?(.{10})$/\1/p'
. If it works, you have carriage returns in your line endings.