Quantcast
Channel: linuxadmin: Expanding Linux SysAdmin knowledge
Viewing all articles
Browse latest Browse all 17793

Crosspost from /r/commandline. Here is a command I came up with some time ago. It goes through plain files to do text replacement.

$
0
0

Just thought to give you guys something back for all the help you have given me in here. You may or may not find this useful.

Note: The command gets stuck in binary files. It works on plain files only. If somebody can make it smart enough to avoid specific type of files OR better yet make it so that it locks on specific files while ignoring all others, more power to you. I would kindly request though for you to post it here so we can all share. Also note that old Linux/Unix boxes have an issue with the format of this command.

1st command) It creates a log file of files it has found with the value of the variable you are looking for. It is good to keep track of your work.

 find /directory/location -type f -exec grep -lr -e "$old_server_name" '{}' ';' >> Migration_change_log_files."$new_server_name" 

2nd command) Goes into a directory and replaces "old_server_name" with "new_server_name". It does it on all of the plain files.

 find /directory/location -type f -exec grep -lr -e "$old_server_name" '{}' \; | xargs sed -i 's/'"$old_server_name"'/'"$new_server_name"'/g' 

I had combine these commands with some for loops that picked up on what type of server a machine was and based on that it would go into the specific directory. Anywho, just thought to give you guys something back for all the help you have given me in here.

submitted by GromitRacer
[link][2 comments]

Viewing all articles
Browse latest Browse all 17793

Trending Articles