Please consider this snippet:
X=$(grep -m1 'some-pattern' some-file | sed -n 's/.* //p')
I want to put last word in a variable if some pattern condition is matched for lines in arbitrary text file
My problem is that variable
X has CR or LF or CRLF at the end, depending on source file, which I want to get rid of, as it interferes with later operation I intend to do.
I even tried something like:
X=$(grep -m1 'some-pattern' some-file | sed -n 's/.* \([A-Za-z]\+\)/\1/p')
sed output to be limited on
[A-Za-z]+ but there are still this nuisance bytes inside X variable.
How can I get rid of it, without using too much code like see what bytes are at the end with
cut it and similar complications?