Skip to main content
deleted 5 characters in body
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 117

With sed:

sed -E 's/^([^\]*[\]){3}//' infile

or the same in awk:

awk '{ sub(/([^\\]*[\\]){3}/, "") }1' infile

Match repeated of (regex) 3times; [^\]*[\] matches on zero-or-more of any-characters but not a back-slash (plus not a newline exceptionally) followed by a back-slash character.


And the bashshell (POSIX sh/bash/Korn/zsh) solution you tagged and asked for:

$ str='hku\test\user\software\microsoft\windows\currentversion\runonce\delete cached update binary'
$ for ((i=0;i i<3;in i++)$(seq 3); do str="${str#*\\}"; done
$ printf '%s\n' "$str"

The ${parameter#word} syntax is the Parameter Expansion, that strips the shortest prefix from its parameter.

With sed:

sed -E 's/^([^\]*[\]){3}//' infile

or the same in awk:

awk '{ sub(/([^\\]*[\\]){3}/, "") }1' infile

Match repeated of (regex) 3times; [^\]*[\] matches on zero-or-more of any-characters but not a back-slash (plus not a newline exceptionally) followed by a back-slash character.


And the bash solution you tagged and asked for:

$ str='hku\test\user\software\microsoft\windows\currentversion\runonce\delete cached update binary'
$ for ((i=0; i<3; i++)); do str="${str#*\\}"; done
$ printf '%s\n' "$str"

The ${parameter#word} syntax is the Parameter Expansion, that strips the shortest prefix from its parameter.

With sed:

sed -E 's/^([^\]*[\]){3}//' infile

or the same in awk:

awk '{ sub(/([^\\]*[\\]){3}/, "") }1' infile

Match repeated of (regex) 3times; [^\]*[\] matches on zero-or-more of any-characters but not a back-slash (plus not a newline exceptionally) followed by a back-slash character.


And the shell (POSIX sh/bash/Korn/zsh) solution:

$ str='hku\test\user\software\microsoft\windows\currentversion\runonce\delete cached update binary'
$ for i in $(seq 3); do str="${str#*\\}"; done
$ printf '%s\n' "$str"

The ${parameter#word} syntax is the Parameter Expansion, that strips the shortest prefix from its parameter.

added 77 characters in body
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 117

With sed:

sed -E 's/^([^\]*[\]){3}//' infile

or the same in awk:

awk '{ sub(/([^\\]*[\\]){3}/, "") }1' infile

Match repeated of (regex) 3times; [^\]*[\] matches on zero-or-more of any-characters but not a back-slash (plus not a newline exceptionally) followed by a back-slash character.


And the bash solution you tagged and asked for:

$ str='hku\test\user\software\microsoft\windows\currentversion\runonce\delete cached update binary'
$ for ((i=0; i<3; i++)); do str="${str#*\\}"; done
$ printf '%s\n' "$str"

The ${parameter#word} syntax is the Parameter Expansion, that strips the shortest prefix from its parameter.

With sed:

sed -E 's/^([^\]*[\]){3}//' infile

Match repeated of (regex) 3times; [^\]*[\] matches on zero-or-more of any-characters but not a back-slash (plus not a newline exceptionally) followed by a back-slash character.


And the bash solution you tagged and asked for:

$ str='hku\test\user\software\microsoft\windows\currentversion\runonce\delete cached update binary'
$ for ((i=0; i<3; i++)); do str="${str#*\\}"; done
$ printf '%s\n' "$str"

The ${parameter#word} syntax is the Parameter Expansion, that strips the shortest prefix from its parameter.

With sed:

sed -E 's/^([^\]*[\]){3}//' infile

or the same in awk:

awk '{ sub(/([^\\]*[\\]){3}/, "") }1' infile

Match repeated of (regex) 3times; [^\]*[\] matches on zero-or-more of any-characters but not a back-slash (plus not a newline exceptionally) followed by a back-slash character.


And the bash solution you tagged and asked for:

$ str='hku\test\user\software\microsoft\windows\currentversion\runonce\delete cached update binary'
$ for ((i=0; i<3; i++)); do str="${str#*\\}"; done
$ printf '%s\n' "$str"

The ${parameter#word} syntax is the Parameter Expansion, that strips the shortest prefix from its parameter.

added 257 characters in body
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 117

With sed:

sed -E 's/^([^\]*[\]){3}//' infile

Match repeated of (regex) 3times; [^\]*[\] matches on zero-or-more of any-characters but not a back-slash (plus not a newline exceptionally) followed by a back-slash character.


And the bash solution you tagged and asked for:

$ str='hku\test\user\software\microsoft\windows\currentversion\runonce\delete cached update binary'
$ for ((i=0; i<3; i++)); do str="${str#*\\}"; done
$ printf '%s\n' "$str"

The ${parameter#word} syntax is the Parameter Expansion, that strips the shortest prefix from its parameter.

With sed:

sed -E 's/^([^\]*[\]){3}//' infile

Match repeated of (regex) 3times; [^\]*[\] matches on zero-or-more of any-characters but not a back-slash (plus not a newline exceptionally) followed by a back-slash character.

With sed:

sed -E 's/^([^\]*[\]){3}//' infile

Match repeated of (regex) 3times; [^\]*[\] matches on zero-or-more of any-characters but not a back-slash (plus not a newline exceptionally) followed by a back-slash character.


And the bash solution you tagged and asked for:

$ str='hku\test\user\software\microsoft\windows\currentversion\runonce\delete cached update binary'
$ for ((i=0; i<3; i++)); do str="${str#*\\}"; done
$ printf '%s\n' "$str"

The ${parameter#word} syntax is the Parameter Expansion, that strips the shortest prefix from its parameter.

deleted 3 characters in body
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 117
Loading
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 117
Loading