Skip to content

Tag: replace

linux replace string in files recursively

I have a folder which is full of *.java files. it has the following method in it: i wanted to change this as following: I have searched in the forum and found some solutions, replce string is what i wanted so tried the following: But it throwing me the following error: I guess the old_string and new_string fo…

Search and Replace ( multiple lines )

Hello StackOverflow Community! I’m working on a bash script to change in Dynamic text file, I want to replace multiple lines with one line. Ex: This example, I want to replace THIS With KKKKK Before script After script I found a script to replace using ( sed ) but it doesn’t replace multiple lines…

Insert text if column contains a number

I have a tab-delim file that looks like this It should be three columns but some rows are missing the second column (bacterial taxonomy). For these rows I want to move the number to a third column and insert some text (such as Unclassified). I have been attempting to modify some commands I found online to ins…

Inserting text in a ‘find’ command search

I have a find string that finds all the instances of a particular filename in a path, like so: I need to return the result with ‘FINENAME=’ prepended on each line. Having a hard time figuring the best way. Answer Note that if you have a directory named /opt/logs (and you’re not trying to loo…

find and replace a String in vi editor on linux?

i am trying to replace String with new String in Linux vi editor but getting following error. Answer I’d guess the reason you’re getting that error message is because you intend to replace the string on all lines, not just the current one. In order to search all lines, add a % to your command: