0

I have the following file test.txt

node1
node2
node3
node4

I want to add the string "1" next to it after a space next to the word node2 using sed so it looks like this.

node1
node2 1
node3
node4

I tried sed '/node2/a 1' test.txt but it adds a new line. How do I just add a space followed by a 1.

1
  • s/node2/node2 1/? Commented May 22, 2020 at 0:05

1 Answer 1

2

a is for adding new lines. Use s to modify the line in place.

sed '/node2/s/$/ 1/' test.txt
Sign up to request clarification or add additional context in comments.

2 Comments

this is perfect, if you dont mind could you take a look at stackoverflow.com/questions/61945793/…
You need to make some attempt to solve the problem yourself. awk would be easier for that problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.