Reputation: 1187
I have a file which consists of following hundred lines in addition to other data
(abc-wxyz1/2222 1234)
1234 is a random number which is different for all the 100 lines. I want to substitute all the lines with
(abc-wxyz1/2222 *)
I am using following code for it
cat input.txt | \
sed -i -e 's/\(abc\-wxyz1\/2222\ [0-9]\+\)/\(abc\-wxyz1\/2222\ \*\)/g' > output.txt
I get the output.txt blank I have no clue why. Am I doing it correctly ?
Upvotes: 1
Views: 1105
Reputation: 38195
For the input sample you've shown, you could go with awk
:
awk '{print $1 " *)"}' input.txt
Upvotes: 1
Reputation: 124
Use this command to see what will be the result of filter:
cat input.txt | sed 's/\(abc\-wxyz1\/2222\ [0-9]\+\)/\(abc\-wxyz1\/2222\ \*\)/g'
Try using shorter patterns to toubleshoot where it is breaking.
You only need the '-e' flag if you have additional commands to run. You could also just do:
sed 'command;command2;{command3}'
Upvotes: 0
Reputation: 14778
If you're going to use the flag -i, --in place
, you don't have to redirect the output. The substitutions are performed in place, as expected.
Yet, you can simplify your expression, doing:
sed -i -e 's/abc\-wxyz1\/2222\ \([0-9]\+\)/*/g' input.txt
Upvotes: 0