Remove the first part of each line of a text file
By John Parsons •
I am trying to edit a text file which has multiple lines that look like this:
avaya logs 20171202 000000 (9).txt: 660119211mS CMLOGGING: CALL:2017/12/0111:14,00:00:16,008,203,O,208,208,Jon,,,1,,""n/a,0I want to remove everything before where it says CALL on every line.
I think the sed command can do this but I am not very familiar with it.
How can I do this?
2 Answers
You can use awk in the following way:
awk -F "CALL" '{print "CALL"$2}' filename The result is:
CALL:2017/12/0111:14,00:00:16,008,203,O,208,208,Jon,,,1,,""n/a,0Details:
- Use the
-For--field-separatorflag, and setting CALL to be the field seperator - Print the string "CALL" followed by
- The second element in the line (when CALL is the separator)
0Note: You can redirect the output into another file using:
awk -F "CALL" '{print "CALL"$2}' filename > newfilename
With sed:
sed -e 's/.*CALL:/CALL:/' input.txt > output.txtIf you want to edit the input file in place add the -i option.