Tuesday, November 29, 2005

unix tip: one-liner find & replace string

normally people use sed to find & replace string.
eg:

$ cat test
abc def xyz 123 456 789
$ sed 's/abc/123/g' test
123 def xyz 123 456 789

but the output is sent to stdout (the screen) not to the file unless you redirect it to new file.
you can use perl to do that.
eg:

$ cat test
abc def xyz 123 456 789
$ perl -pi -e 's|abc|123|g' test
$ cat test
123 def xyz 123 456 789

to backup the original file use -pi.bak option & your original file will be saved as .bak

Wednesday, November 16, 2005

unix tip: ps - full listing of the processes name

to get full listing of the processes name when using ps
for linux, you can use -w option.
eg:

$ ps -auxww

for aix, you can use -l option.
$ ps -elf

but for solaris, the processes name get truncated when you use -l option, so it is sufficient to use ps -ef only.


Wednesday, November 02, 2005

unix tip: return to previous directory

for linux if u want to return to previous directory u can type.
eg:

$ cd -

this also works for solaris & hpux. ooopss also works for aix, but if not working u can try this.
$ cd ~-

i suspect it's depend on your shell... hmmm no idea...