Tuesday, October 31, 2006
Find and Replace in VI
I am trying to change all occurances of /a1/a2 with /a1/b1 in a file. How to do it
1. in vi editor?
2. from command prompt?
Ans :
:1,$ s/\/a1\/a2/\/a1\/b1/g
I am trying to change all occurances of xxx with yyy in a file. How to do it
1. in vi editor?
2. from command prompt?
Ans :
:1,$ s/xxx/yyy/g OR :%s/xxx/yyy/g
OR with out opening the VI Editor you can try sed 's/xxx/yyy/g' filename > filename2
1. in vi editor?
2. from command prompt?
Ans :
:1,$ s/\/a1\/a2/\/a1\/b1/g
I am trying to change all occurances of xxx with yyy in a file. How to do it
1. in vi editor?
2. from command prompt?
Ans :
:1,$ s/xxx/yyy/g OR :%s/xxx/yyy/g
OR with out opening the VI Editor you can try sed 's/xxx/yyy/g' filename > filename2
Tuesday, October 24, 2006
CronJob Issues with shellScripts and Perl Scripts
When you are putting ShellScripts or Perl Scripts in CronJob. Following points are note worthy.
1. The environment variables in your Shell are not carried over in a CronJob.
Bcoz when a script is invoked from a CronJob the .bashrc is not scourcd
- !! soln !! - source .bashrc in your shell script
2. Allways use FULL and ABSOLUTE path for files and scripts in your PERL and SHELLSCRIPTS.
1. The environment variables in your Shell are not carried over in a CronJob.
Bcoz when a script is invoked from a CronJob the .bashrc is not scourcd
- !! soln !! - source .bashrc in your shell script
2. Allways use FULL and ABSOLUTE path for files and scripts in your PERL and SHELLSCRIPTS.
Wednesday, October 04, 2006
Remiving files/folders based on date
Look at the manpage for the "find" command. Here is an example of what you want.
find /var/log -mtime +60 -type f -exec rm -rf {} \;
This command will do a search in /var/log for all files that were last modified 60 or more days ago and executes a recursive forced (-rf) remove (rm). The "{}" (curly braces) is the place holder for exec to use where it will put the name of the file, and the "\;" tells exec that's the end of the statement. Find is very powerful, and I suggest you do some reading BEFORE you do any removing using "find". Also, as a test you can replace the "rm -rf" with "ls -la" to get a list of all the files that would be removed. And, if you want to remove files with specific names or extensions use the "-name" argument.
find /var/log -mtime +60 -type f -exec rm -rf {} \;
This command will do a search in /var/log for all files that were last modified 60 or more days ago and executes a recursive forced (-rf) remove (rm). The "{}" (curly braces) is the place holder for exec to use where it will put the name of the file, and the "\;" tells exec that's the end of the statement. Find is very powerful, and I suggest you do some reading BEFORE you do any removing using "find". Also, as a test you can replace the "rm -rf" with "ls -la" to get a list of all the files that would be removed. And, if you want to remove files with specific names or extensions use the "-name" argument.