Showing posts with label vi. Show all posts
How to replace ^M in unix to nothing?
Monday, May 3, 2010
If you saw a lot of ^M character in your code, reason being is ^M is the character in DOS if you create the file in Windows.
If you transfer the DOS file into unix, you will see lots of ^M in your file and it is very irritating indeed.
You can do a simple magic in vi by
:%s/[crtl-v ctrl-m//g
meaning,
%s - substitute
[ctrl-v ctrl-m] - create the ^M character
// - empty
g - replace globally
Posted in Unix, vi by Alex Yap | 0 comments
Email this postHow to use regular expression (regex) in grep or vi?
Wednesday, July 8, 2009
How to use regular expression (regex) in grep or vi?
If you need to search for a pattern of "string" or "character" in a file / many files, you will need to use regular expression (regex) either in vi editor or in grep command. But how? See below:
using vi:
- press '/' for searching
- for instance, i wanted to search for CL000, CL001, CL002, ie: the pattern is CLXXX follow by digit.
- syntax:
/^CL[0-9]*
^ - start of pattern
* - zero or more digit
using unix grep command:
- grep CL[0-9]
Posted in Unix, vi, vim by Alex Yap | 0 comments
Email this post
Subscribe to:
Posts (Atom)