-1

I have a problem with making sed command, which gonna change lines, where =sometext= occurs and change it to another pattern, but will not do it when https occcurs in that line. I have no idea how I should change this command:sed -i 's/=\([^=]*\)=/{{\1}}/g'

Mark
  • 43
  • 7
  • similar question with answers: https://stackoverflow.com/questions/9053100/sed-regex-and-substring-negation – sborsky Mar 07 '19 at 15:47
  • Maybe something like `awk '!/https/ && /=sometext=/{gensub(/=([^=]*)=/, "\1", $0)}1' file` with gawk. Can't test now though. – Wiktor Stribiżew Mar 07 '19 at 15:51

2 Answers2

1

You'll want to read the sed manual about matching lines: https://www.gnu.org/software/sed/manual/sed.html chapter 4:

The following command replaces the word ‘hello’ with ‘world’ only in lines not containing the word ‘apple’:

sed '/apple/!s/hello/world/' input.txt > output.txt
Community
  • 1
  • 1
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
1

Use multiple blocks, e.g.:

sed '/=sometext=/ { /https/b; s/.../.../; }'
Thor
  • 45,082
  • 11
  • 119
  • 130