What is "script":
Sample Output:
Before Formatting:
Find & Replace Characters:
After Formatting:
Linux is having an utility to log the output displayed on the screen console. This utility is invoked using the "script" command.
How to invoke script:
script <file-name>
The above command will create a text file in the "file-name" and then will start to log all the outputs displayed on the screen into this file.
Note: If the file with name "file-name" already present, then it will be overwritten.
Formatting the "script" output file:
The output file generated using the script command, will have some special/unwanted characters. These can be cleaned up using the "vim" editor's regular expression matching.
In most cases, you will find the special characters like ^M, ^H, etc. in the output of script command. This can be cleaned up using the below "vim" commands.
Step | Command |
---|---|
Open the file using vim editor | vim "file-name" |
Go to the command mode | Press ESC key |
Give the command. This command will remove all the occurrences of the character "^M". The "<ctrl-v><ctrl-m>" combination will be encoded to "^M" | :%s/<ctrl-v><ctrl-m>//g |
- Note: Similarly we can give remove any special characters using the combination of "<ctrl-v><ctrl-X>", where X = H,G, or any special character present in the file.
- If the character "^M" present at the end of the line, then use the command "":%s/<ctrl-v><ctrl-m>\n/\r/g" to replace it with the line break.
Sample Output:
Before Formatting:
Find & Replace Characters:
After Formatting:
No comments:
Post a Comment