Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

word substitution with incremented number

I have a large text file where the word DATA appears more than 10000 times. I would like to know how can a make a conditional substitution, so the first time it appears in the document it is changed to NO1 and the second time to NO2 and so on, using bash. I was thinking about some complicated script using bash but there must be an easier way, I guess.

like image 922
Open the way Avatar asked Dec 31 '25 23:12

Open the way


1 Answers

perl -pe 's/DATA/ "NO" . ++$n /ge' file_in > file_out
like image 96
glenn jackman Avatar answered Jan 06 '26 05:01

glenn jackman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!