1) CONTROL M (^M)CHARACTERS : This is one of the most common problem while working on UNIX and WINDOWS system.Whenever you move any file from WINDOWS system to UNIX you must make sure that you select transfer type as TEXT for your data files else CONTROL M (^M) characters will be appended at the end of each line.
You may use FILEZILLA or WINSCP for file transferring and select transfer type as TEXT.However if you want to use some script or UNIX code for removing control M characters then try this code :
Removes control characters (^M) :

sed 's/.$//' oldfilename >newfilename

This one liner sed command removes Control M characters at the end.

Other way of doing same thing suggested by my friend Rahul is :
to remove this open a file in vi command line mode and type the following command


: – colon i to start a command in vi
1,$ 1 is the start point and $ is the end point
control+v+m is the pattern to be searched for
empty replace string
g is an variable modifier in pattern matching which means globally and replace all the occurence of the matched string

2) Search for FILES with specific keyword as content : If you want to search for files having some keyword  as its content.I repeat as its content and not filename itself then you can use below command for easily searching for files having KEYWORD as its content.

grep -il "KEYWORD" `find . -name "*.*" -type f -print`

3) Create a LOG file : If you want to create a log file for your UNIX script so that you can maintain logs and check for any errors then you can use below one liner for the purpose.
exec > LOGFILE.log 2>&1
This command will redirect all the STANDARD OUTPUT and STANDARD ERRORS to file named LOGFILE.log

If you know some other helpful commands then do share it here.
For any queries regarding above statements feel free to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *