M BUZZ CRAZE NEWS
// news

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,0

I 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?

1

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,0

Details:

  1. Use the -F or --field-separator flag, and setting CALL to be the field seperator
  2. Print the string "CALL" followed by
  3. The second element in the line (when CALL is the separator)

Note: You can redirect the output into another file using:

awk -F "CALL" '{print "CALL"$2}' filename > newfilename

0

With sed:

sed -e 's/.*CALL:/CALL:/' input.txt > output.txt

If you want to edit the input file in place add the -i option.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy