Monday, March 27, 2017

Bash: Scripting: Search and Replace Text


Search and Replace Text


# cat data6.txt
This is line number 1.
This is line number 2.
This is line number 3.
This is line number 4.


# rep=$(grep -i number data6.txt)

# echo ${rep/number/No.}
This is line No. 1. This is line number 2. This is line number 3. This is line number 4.


This only change the first instance of number.

To change all instances of number change the first / to a double //.


# echo ${rep//number/No.}
This is line No. 1. This is line No. 2. This is line No. 3. This is line No. 4.

No comments:

Post a Comment