LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed help (https://www.linuxquestions.org/questions/linux-newbie-8/sed-help-4175672857/)

motherboard 04-09-2020 08:39 AM

sed help
 
echo "test start random stuff in here finish test" | sed -e 's/start*finish//'
echo "test start random stuff in here finish test" | sed -e '/start/,/finish/d'

I want to delete from start to finish. The result should be "test test".

Turbocapitalist 04-09-2020 08:45 AM

The first line is missing a symbol right before the asterisk and after the "t". Right now you have it matching any number of the letter "t", since in regular expressions the asterisk works on the preceding symbol. It does not in and of itself match anything, like it would in globbing.

Hint: https://www.rexegg.com/regex-quickstart.html#morechars

ychaouche 04-09-2020 10:03 AM

Quote:

Right now you have it matching any number of the letter "t"
So it should match for one occurence. The problem is that you only allow any number of t characters, and nothing else. So startttttttttfinish and starfinish would match, but not start to finish for example. Try start.*finish rather.

The second line you are using a sed range (/pattern1/,/pattern2/) and the d command which is for delete. Use this when you want to remove a range of lines, starting from the first occurence of pattern1 until the first occurence of pattern2.


All times are GMT -5. The time now is 08:42 PM.