Skip to main content
added 146 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

I'm assuming your substitution fails because the two columns in your input file are tab-delimited, not space-delimited.

Instead of a space in your regular expression, you may use a literal tab character (typed on the command line using Ctrl+V Tab), or you may use an expression that represents a tab, such as [[:blank:]] (matches a single tab or space character) or [[:space:]] (matches a single character from a larger set of space-like characters, including horizontal and vertical tabs, carriage-returns, etc.)

sed -e 's|^1344P1052_ssl02[[:blank:]]/gs:/prod1|sdprod1/|sd://prod1-backup|'backup/|' \
    -e 's|^1344P1052_ssl09[[:blank:]]/gs:/prod1|sdprod1/|sd://prod1-backup|'backup/|' \
    -i example.txt

or, even shorter,

sed -e 's|^1344P1052_ssl0[29][[:blank:]]/gs:/prod1|sdprod1/|sd://prod1-backup|'backup/|' \
    -i example.txt

I've replaced the space in your pattern with [[:blank:]]. This allows for a single space-or-tab character at that point in the text. I have also combined the two substitutions into a single sed call to avoid reading the whole file twice. I deleted the g flag on both substitution commands as we don't ever expect to make more than a single substitution per line, and I added a ^ anchor to ensure that the patterns match at the start of each line.

  • I've replaced the space in your pattern with [[:blank:]]. This allows for a single space-or-tab character at that point in the text.
  • I have also combined the two substitutions into a single sed call to avoid reading the whole file twice.
  • I deleted the g flag on both substitution commands as we don't ever expect to make more than a single substitution per line.
  • I added a ^ anchor to ensure that the patterns match at the start of each line.
  • I added a / at the end of the pattern and replacement string to not accidentally change lines relating to prod10 or higher-numbered prod things.

I'm assuming your substitution fails because the two columns in your input file are tab-delimited, not space-delimited.

Instead of a space in your regular expression, you may use a literal tab character (typed on the command line using Ctrl+V Tab), or you may use an expression that represents a tab, such as [[:blank:]] (matches a single tab or space character) or [[:space:]] (matches a single character from a larger set of space-like characters, including horizontal and vertical tabs, carriage-returns, etc.)

sed -e 's|^1344P1052_ssl02[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -e 's|^1344P1052_ssl09[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

or, even shorter,

sed -e 's|^1344P1052_ssl0[29][[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

I've replaced the space in your pattern with [[:blank:]]. This allows for a single space-or-tab character at that point in the text. I have also combined the two substitutions into a single sed call to avoid reading the whole file twice. I deleted the g flag on both substitution commands as we don't ever expect to make more than a single substitution per line, and I added a ^ anchor to ensure that the patterns match at the start of each line.

I'm assuming your substitution fails because the two columns in your input file are tab-delimited, not space-delimited.

Instead of a space in your regular expression, you may use a literal tab character (typed on the command line using Ctrl+V Tab), or you may use an expression that represents a tab, such as [[:blank:]] (matches a single tab or space character) or [[:space:]] (matches a single character from a larger set of space-like characters, including horizontal and vertical tabs, carriage-returns, etc.)

sed -e 's|^1344P1052_ssl02[[:blank:]]/gs:/prod1/|sd://prod1-backup/|' \
    -e 's|^1344P1052_ssl09[[:blank:]]/gs:/prod1/|sd://prod1-backup/|' \
    -i example.txt

or, even shorter,

sed -e 's|^1344P1052_ssl0[29][[:blank:]]/gs:/prod1/|sd://prod1-backup/|' \
    -i example.txt
  • I've replaced the space in your pattern with [[:blank:]]. This allows for a single space-or-tab character at that point in the text.
  • I have also combined the two substitutions into a single sed call to avoid reading the whole file twice.
  • I deleted the g flag on both substitution commands as we don't ever expect to make more than a single substitution per line.
  • I added a ^ anchor to ensure that the patterns match at the start of each line.
  • I added a / at the end of the pattern and replacement string to not accidentally change lines relating to prod10 or higher-numbered prod things.
added 131 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

I'm assuming your substitution fails because the two columns in your input file are tab-delimited, not space-delimited.

Instead of a space in your regular expression, you may use a literal tab character (typed on the command line using Ctrl+V Tab), or you may use an expression that represents a tab, such as [[:blank:]] (matches a single tab or space character) or [[:space:]] (matches a single character from a larger set of space-like characters, including horizontal and vertical tabs, carriage-returns, etc.)

sed -e 's|^1344P1052_ssl02[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -e 's|^1344P1052_ssl09[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

or, even shorter,

sed -e 's|^1344P1052_ssl0[29][[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

I've replaced the space in your pattern with [[:blank:]]. This allows for a single space-or-tab character at that point in the text. I have also combined the two substitutions into a single sed call to avoid reading the whole file twice. I deleted the g flag on both substitution commands as we don't ever expect to make more than a single substitution per line, and I added a ^ anchor to ensure that the patterns match at the start of each line.

I'm assuming your substitution fails because the two columns in your input file are tab-delimited, not space-delimited.

Instead of a space in your regular expression, you may use a literal tab character (typed on the command line using Ctrl+V Tab), or you may use an expression that represents a tab, such as [[:blank:]] (matches a single tab or space character).

sed -e 's|^1344P1052_ssl02[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -e 's|^1344P1052_ssl09[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

or, even shorter,

sed -e 's|^1344P1052_ssl0[29][[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

I've replaced the space in your pattern with [[:blank:]]. This allows for a single space-or-tab character at that point in the text. I have also combined the two substitutions into a single sed call to avoid reading the whole file twice. I deleted the g flag on both substitution commands as we don't ever expect to make more than a single substitution per line, and I added a ^ anchor to ensure that the patterns match at the start of each line.

I'm assuming your substitution fails because the two columns in your input file are tab-delimited, not space-delimited.

Instead of a space in your regular expression, you may use a literal tab character (typed on the command line using Ctrl+V Tab), or you may use an expression that represents a tab, such as [[:blank:]] (matches a single tab or space character) or [[:space:]] (matches a single character from a larger set of space-like characters, including horizontal and vertical tabs, carriage-returns, etc.)

sed -e 's|^1344P1052_ssl02[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -e 's|^1344P1052_ssl09[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

or, even shorter,

sed -e 's|^1344P1052_ssl0[29][[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

I've replaced the space in your pattern with [[:blank:]]. This allows for a single space-or-tab character at that point in the text. I have also combined the two substitutions into a single sed call to avoid reading the whole file twice. I deleted the g flag on both substitution commands as we don't ever expect to make more than a single substitution per line, and I added a ^ anchor to ensure that the patterns match at the start of each line.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

I'm assuming your substitution fails because the two columns in your input file are tab-delimited, not space-delimited.

Instead of a space in your regular expression, you may use a literal tab character (typed on the command line using Ctrl+V Tab), or you may use an expression that represents a tab, such as [[:blank:]] (matches a single tab or space character).

sed -e 's|^1344P1052_ssl02[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -e 's|^1344P1052_ssl09[[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

or, even shorter,

sed -e 's|^1344P1052_ssl0[29][[:blank:]]/gs:/prod1|sd://prod1-backup|' \
    -i example.txt

I've replaced the space in your pattern with [[:blank:]]. This allows for a single space-or-tab character at that point in the text. I have also combined the two substitutions into a single sed call to avoid reading the whole file twice. I deleted the g flag on both substitution commands as we don't ever expect to make more than a single substitution per line, and I added a ^ anchor to ensure that the patterns match at the start of each line.