Blog Logo Screenlight Blog

Linux Commandline Search-and-Replace

code example

Schon mal ein search-and-replace in einem File in einer Linux shell automatisieren wollen?
sed ist eine sehr schöne Lösung!

sed -i ‘s/[orginal_text]/[new_text]/’ filename.txt

Das beste ist, man darf darin Regex verwenden.

Here’s the breakup of the above command. First you call the “sed” command. Then you pass it the parameter “-s” which stands for “in place of”. Now we use a little bit of regular expressions, commonly known as “regex” for the next bit. The “s” in the quoted string stands for “substitute”, and the “g” at the end stands for “global”. Between them they result in a “global substitution of the the string of text you place in between them.

Hier gefunden

Leave a Response

No comments so far, would you like to be the first?