3:44 PM Remove Control M characters from a script or any file in Linux/AIX |
Hi Guys, Being a consultant in DBS project I have witnessed many cased where the shell script that is copied or created may contain some special characters. This happens when the script is copied from windows system to AIX and the script was having extra spaces. So, if the script is having such speciall characters, it might not get executed successfully throwing error as below:
Command not found: ^M
The solution is we have to find and remove all special characters like these from the script. Here we shall practice a very simple way to do the same. 1. Using command tr. Example:
-d option is used to delete any specified characters from the file.
2. Using Vi editor Open the file in Vi editor. Use the substitute method as below :%s/^M//g It means search for ^M and replace it with nothing globally if the flag 'g' is given. 3. Using SED We can use SED command also to modify the file on the go. Use -i option to backup the file before making any changes. Example:
The file will be modified and a backup will also be created with .bak extension.
Please Like/Share/comment if you find this useful. |
|
Related blogs
You may also like to see:
[2015-03-23] | [Open System-Linux] |
FSCK : Checking and reparing filesystems in Linux |
[2014-04-10] | [Open System-Linux] |
SED command for filtering and transforming texts of a file using regular expression |
[2014-09-26] | [Open System-Linux] |
Traceroute command in Linux |
[2014-09-21] | [Open System-Linux] |
How to define command prompt strings in Linux : what are $PS1, $PS2, $PS3 and $PS4? |
[2015-06-13] | [Open System-Linux] |
XRANDR command : a command line interface to RandR extension, set screen size and orientation |
Total comments: 0 | |