Issue
I wanted to use grep to exclude words from $lastblock by using a pipeline, but I found that grep works only for files, not for stdout output.
So, here is what I'm using:
class="lang-sh prettyprint-override">lastblock="./2.json"
echo $lastblock | sed '1,/firstmatch/d;/.json/,$d'
I want to exclude ./
and .json
, keeping only what is between.
This sed command is correct for this purpose, but how to escape the ./
replacing firstmatch
so it can work?
Thanks in advance!
Solution
Solution!
Just discovered today the tr
command thanks to this legendary, unrelated answer.
When searching all over Google for how to exclude "." and "/", 100% of StackOverflow answers didn't helped.
So, to escape characters from the output of a command, just append this pipe:
| tr -d "{character-emoji-anything-you-want-to-exclude}"
So, a full working and simple sample:
echo "./2.json" | tr -d "/" | tr -d "." | tr -d "json"
And done!
Answered By - dani 'SO learn value newbies' Answer Checked By - Willingham (WPSolving Volunteer)