0

say I have the following the text file :

.................
value1= "2000";
justAtext= "hello Text" 
..................................

my question is, is there any linux cmd that would allow me to search into the file for example for "value" and than replace the whole line with something else like:

.................
changedText= "Hello";
justAtext= "hello Text" 
..................................

thanks in advance for any hint!

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Engine
  • 5,360
  • 18
  • 84
  • 162

1 Answers1

0

Yes there are several methods for doing it. The fastest IMO:


input

.................
value1= "2000";
justAtext= "hello Text" 
..................................

Assume this text is on a file named foo.txt


elaboration

sed -iE 's/value1=.*/changedText= "Hello";/g' foo.txt

  • -i -> replace content on the same file (omitting this option the output will be printed on the Standard Output)
  • -E -> use regex

output

.................
changedText= "Hello";
justAtext= "hello Text" 
..................................
Roberto Manfreda
  • 2,345
  • 3
  • 25
  • 39