We had these log files that on most lines at the beginning there was a number followed by a dot and some times it had space characters.
The following sed command removes that prefix. and leaved intact the rest of the lines that do not have the prefix.
1
cat$log | sed'/^[0-9]*. */!d; s///;q';
e.g
Input: 123. Some text here.
Output:Some text here.
Remove leading whitespace (space and tabs) from line:
The following sed script will remove all leading whitespace from each line by using a regular expression to match space characters and tabs.
In the above example we have as input the variable string that contains following /scripts/log/mount_hello_kitty.log. We want to remove from that variable the prefix, which is /scripts/log/mount_ and the suffix, which is .log. The above code will replace in place the input that is contained in the variable string and…
Following is a small snippet that will print on screen the IP of enp0s3 (or any other device if you change the name) while in Fedora. As you will see, it is not a very sound solution as it depends on the structure of the output of ifconfig enp0s3. Nevertheless…
Scenario You have many simple text log files of a system, where the date is formatted using the slash character / and you want to update the dates to some other date. Usually when using the sed, the slash character is reserved for separating the parts of the expression you…