Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

How to change ^M line break to 'normal' line break in a file Which is opened using VIM Editor

How to change ^M line break to 'normal' line break in a file Which is opened using VIM Editor

Most of the experienced with ^M line break characters in opened files in Vim editor. Please find the solution below to change in to normal

 %s/ Ctrl-V Ctrl-M //g

In the above statement

 Ctrl-V Ctrl-M means type Ctrl+V then Ctrl+M. 
Explanation
:%s --> substitute
 ^M characters (the Ctrl-V is a Vim way of writing the Ctrl ^ character)
//
with "" (NULL) characters (the character between the 2 forward-slash / characters)
g --> And do it globally (not just the first occurrence on the line).
Happy learning ..:)

How to search/find specific string in Linux and Solaris

How to search/find specific string in Linux and Solaris
In this post we are going learn about how to find search string in files and folders in Linux and Solaris machines. The list of techniques are describe below
grep -rnw 'directory' -e "pattern"
-r is recursive, -n is line number and -w stands match the whole word. Along with these, --exclude or --include parameter could be used for efficient searching. Something like below:
grep --include={*.c,*.h} -rnw 'directory' -e "pattern"
This will only search through the files which have .c or .h extensions. Similarly a sample use of --exclude:
grep --exclude=*.o -rnw 'directory' -e "pattern"
Above will exclude searching all the files ending with .o extension. In post we are going to learn about how to search string in all files in Solaris. Solaris 10 includes grep utility it won't work recursively like in many Linux flavours. We can search strings recursively using the following
$ grep 'search string' `find . -name '*'`
It works well in same directory. We can search strings including sub folders using the following approach
$ find . | xargs grep 'search string'
This is very useful to search strings, but It will take little longer time.