findreplace: find and replace patterns on the UNIX system

findreplace is a powerful command that run on the UNIX system prompt that allows the user to locate patterns in files on the UNIX filesystem. findreplace is run the UNIX terminal and does not require any GUI interface. You can use findreplace to simply locate patterns in files and directories.
You can replace patterns with new patterns. The following example shows how to use findreplace.

1 Cmd#1 on Machine HPMC7 User root
(ndxNo=1 Cmd# No=1 on Machine HPMC7 User root no_tm_u_h_cwd=19:30:29 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:30:29 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern Infiniband
you can use findreplace command just to find a pattern in files located in a directory. for example, here we are looking for the word 'Infiniband' in the current directory ./ or we could have followed -dir by . or ../etc or /tmp/etc all specifying the same target directory

2 Cmd#2 on Machine HPMC7 User root
(ndxNo=2 Cmd# No=2 on Machine HPMC7 User root no_tm_u_h_cwd=19:30:41 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:30:41 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern Infiniband -quiet
the option -quiet is to suppress the printing of all the files that are found by findreplace. we will add it in the following command to shorten the output.

3 Cmd#3 on Machine HPMC7 User root
(ndxNo=3 Cmd# No=3 on Machine HPMC7 User root no_tm_u_h_cwd=19:30:51 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:30:51 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern Infiniband -quiet -nopatcase
the option -nopatcase tell findreplace to ignore the case of the pattern being searched.

4 Cmd#4 on Machine HPMC7 User root
(ndxNo=4 Cmd# No=4 on Machine HPMC7 User root no_tm_u_h_cwd=19:30:59 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:30:59 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern Infiniband -quiet -nopatcase -newpattern INFINITYBAND
to replace the pattern with a new pattern we use the options: -pattern and -newpattern. here findreplace search for the pattern Infiniband to replace with the pattern INFINITYBAND. this command will show what is found and what will be replaced with what, but it does not commit any change.

5 Cmd#5 on Machine HPMC7 User root
(ndxNo=5 Cmd# No=5 on Machine HPMC7 User root no_tm_u_h_cwd=19:31:15 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:31:15 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern Infiniband -quiet -nopatcase
here we added -nopatcase option telling findreplace to ignore the case of the pattern. you can see more files are found to contain the word Infiniband (disregarding the case).

6 Cmd#6 on Machine HPMC7 User root
(ndxNo=6 Cmd# No=6 on Machine HPMC7 User root no_tm_u_h_cwd=19:31:54 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:31:54 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern Infiniband -quiet -nopatcase -newpattern INFINITYBAND -silent
here the option -silent is to silence the replacement-processor and just show that a pattern is found rather then printing what is found and what will be replaced. do not confuse -quiet with -silent. below we repeat the command without the -silent option. also note that no real replacement is taking place yet, that is the command shows you only what will be replaced with what without committing the changes.

7 Cmd#7 on Machine HPMC7 User root
(ndxNo=7 Cmd# No=7 on Machine HPMC7 User root no_tm_u_h_cwd=19:32:26 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:32:26 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern Infiniband -quiet -nopatcase -newpattern INFINITYBAND
we repeat the previous command without the -silent option. note how findreplace prints what is being being replaced with what. the -silent option is usually used when doing batch processing replacement.

8 Cmd#8 on Machine HPMC7 User root
(ndxNo=8 Cmd# No=8 on Machine HPMC7 User root no_tm_u_h_cwd=19:34:2 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:34:2 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern Infiniband -quiet -nopatcase -newpattern INFINITYBAND -commit
here we will really replace the pattern Infiniband with the new pattern INFINITYBAND as the option -commit will commit the changes.

9 Cmd#9 on Machine HPMC7 User root
(ndxNo=9 Cmd# No=9 on Machine HPMC7 User root no_tm_u_h_cwd=19:34:20 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:34:20 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern Infiniband -quiet -nopatcase -newpattern INFINITYBAND
since the changes have been commited there is no more pattern Infiniband as shown in this command.

10 Cmd#10 on Machine HPMC7 User root
(ndxNo=10 Cmd# No=10 on Machine HPMC7 User root no_tm_u_h_cwd=19:35:32 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:35:32 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern INFINITYBAND -quiet
but we can look for the pattern INFINITYBAND and locate them in the files.

11 Cmd#11 on Machine HPMC7 User root
(ndxNo=11 Cmd# No=11 on Machine HPMC7 User root no_tm_u_h_cwd=19:35:46 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:35:46 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern INFINITYBAND -quiet -nopatcase -newpattern InfiniBand
let's undo the replacement of Infiniband with INFINITYBAND, so we will look for the pattern INFINITYBAND and replace it with InfiniBand; however, we do not commit the change.

12 Cmd#12 on Machine HPMC7 User root
(ndxNo=12 Cmd# No=12 on Machine HPMC7 User root no_tm_u_h_cwd=19:36:4 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:36:4 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern INFINITYBAND -quiet
since the change is not commited previously, then the pattern INFINITYBAND still exist.

13 Cmd#13 on Machine HPMC7 User root
(ndxNo=13 Cmd# No=13 on Machine HPMC7 User root no_tm_u_h_cwd=19:38:16 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:38:16 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern INFINITYBAND -quiet -nopatcase -newpattern InfiniBand -commit
here we will redo the change and commit the operation.

14 Cmd#14 on Machine HPMC7 User root
(ndxNo=14 Cmd# No=14 on Machine HPMC7 User root no_tm_u_h_cwd=19:38:37 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:38:37 root@HPMC7 /tmp/etc # findreplace -dir ./ -pattern InfiniBand -quiet
since the change is commited, now we can locate the pattern InfiniBand that we started with.

15 Cmd#15 on Machine HPMC7 User root
(ndxNo=15 Cmd# No=15 on Machine HPMC7 User root no_tm_u_h_cwd=19:38:54 root@HPMC7 /tmp/etc u_h=root@HPMC7)
BASH 19:38:54 root@HPMC7 /tmp/etc #
sweet!