Tuesday, May 14, 2024
35
rated 0 times [  35] [ 0]  / answers: 1 / hits: 126404  / 1 Year ago, sun, april 16, 2023, 12:31:08

I know how to add new text to a file, but how can I edit it?



Example: adding hello_world = 1 to test.txt using the following command:



echo "hello_world = 1" >> test.txt


But how can I change 1 to 0 or something else?


More From » command-line

 Answers
1

Using sed:



sed -i 's/1/0/g' test.txt


In general:



sed -i 's/oldstring/newstring/g' filename


See man sed for more info.


[#24325] Monday, April 17, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
losbu

Total Points: 71
Total Questions: 124
Total Answers: 106

Location: Honduras
Member since Sat, Jul 24, 2021
3 Years ago
;