- “vi tips and tricks: Ten cool commands sure to impress your friends” by Martin Wicks (IBM DeveloperWorks, 2010.07.27) – http://www.ibm.com/developerworks/aix/library/au-vitips.html?ca=dgr-lnxw06VITips10dth-AIX
- “UNIX tips and tricks for a new user, Part 2: The vi text editor” by Tim McIntire (IBM DeveloperWorks, 2006.11.07) – http://www.ibm.com/developerworks/aix/tutorials/au-unixtips2/
- “vi intro — the cheat sheet method” by Daniel Robbins (IBM DeveloperWorks, 2006.11.15) – http://www.ibm.com/developerworks/linux/tutorials/l-vi/
- “Learn Linux, 101: File editing with vi” by Ian Shields (IBM DeveloperWorks, 2010.02.10) – http://www.ibm.com/developerworks/linux/library/l-lpic1-v3-103-8/
- “The vi Lovers Home Page” – http://thomer.com//vi/vi.html
- The vim home page – http://www.vim.org/
- “VI Text Editor Reference Sheet” by Roger Murray (1994.10.19) – http://www.its.caltech.edu/info/Applications/vi.shtml
- “An Introduction to Display Editing with Vi” by William Joy and Mark Horton – http://docs.freebsd.org/44doc/usd/12.vi/paper.html
- Vim – Vi IMproved – http://www.moolenaar.net/vim.html
2010.11.15
vi editor
2010.07.13
Command line based text replace
sed
-
sed 's/Mark Monre/Marc Monroe/' 1.txt > 2.txt
-
find ./* -type f -exec sed -i 's///g' {} \;
The “replace” command
- Syntax:
replace OLD-STRING NEW-STRING OUTPUT-FILE
- Example:
$ replace UNIX Linux newfile
- Example:
$ cat /etc/passwd | replace : '|'
- Partial support for regular expressions: \^ – matches start of line, and $ matches end of line.
- Example: replace all IP address 192.168.1.2 start of line:
$ replace \^192.168.1.2 192.168.5.10 newfile
- a bash script, ‘fixer.sh’
#!/bin/bash replace CHANGEFROM CHANGETO $1.tmp rm $1 mv $1.tmp $1
now run this command line:
$ grep CHANGEFROM |cut -d':' -f1 |xargs -n 1 fixer.sh
the results is that all files in the directory (or whatever you grep for) will be changed automagically.
just make sure the grep doesn’t include the fixer script itself, or it will die half-way through changing when execute permissions are reset!
Perl
- Perl Pie:
perl -p -i -e ’s/hello/goodbye/g’ textfile.txt
- http://www.debian-administration.org/articles/298 has a fine article and discussion on Perl Pie.
-
perl -p -i -e ’s/|00000000.00|/||/g’ myfile.txt
Sources:
- How do I replace text string in many files at once? – http://www.cyberciti.biz/tips/how-do-i-replace-text-string-in-many-files-at-once.html
Related: Regular expressions – https://eikonal.wordpress.com/2010/04/02/regular-expressions/ | Perl online – https://eikonal.wordpress.com/2010/02/15/perl-online/