Tom Tom - 2 months ago 11
Bash Question

What's the parameter call for STDIN when you pipe things into echo or print?

I have some text that I've created using a sting of pipes, and I'd like to further manipulate that using echo instead of awk.

Say that I have:

a chain | of | commands | producing |stream | of text


line 1 text
line 2 text
line 3 text

But if I wanted to use echo to do something like this:

a chain | of | commands | producing |stream | of text | echo ${STDIN%text}

to cut off all text after where it says line, how would I reference that to get this expected result:

line 1
line 2
line 3


A tool like awk is best for your scenario :

a chain | of | commands | awk '{sub(/[[:blank:]]*text$/,"")}1'

sub by default acts on the whole record $0 and will retain the number of spaces/tabs in the text retrieved.

Need more on awk? check [ this ].