1

I have a file with tons of call logs and I am trying to clean it up using bash. I figured out how to search for a string and delete the entire line it is on but that isn't what I want to accomplish.

I want to search for a string as an example:

  • There are tons of MAC address in the file and I want to remove them all MAC:00-0A-DD-84-01-33
  • There is also a call ID at the beginning of each line that looks like: 354469805 or 354469894 and I want to remove all of those as well.

I'm just starting in bash so please excuse my ignorance. I am entering 2 lines of the call log below for clarification. I want to delete the 3544 number, the MAC address, and the word Telepacific.

354469725   06/24/2013  09:34   00:03:26    Chante Squires      105 TelePacific     MAC:00-0A-DD-84-01-1D   TelePacific                 17025290701 1   
354469732   06/24/2013  09:59   00:01:16    Chante Squires      105 TelePacific     MAC:00-0A-DD-84-01-1D   TelePacific                 12132238375 1   
3
  • Please add a few sample lines of input to the question. Commented Jun 27, 2013 at 18:17
  • 1
    sed -i '/regex-pattern/d' file.ext Commented Jun 27, 2013 at 18:20
  • I tried sed -i '/"Telepacific"/d' Nichole24-25 > Nichole but got.. sed: 1: "Nichole24-25": extra characters at the end of N command Commented Jun 27, 2013 at 19:09

2 Answers 2

1

You could use sed:

sed -i 's/^[0-9]\{9\}\|MAC:[0-9A-Fa-f]\{2\}\([-\:][0-9A-Fa-f]\{2\}\)\{5\}//g' input.log

Between the 's/ and //g' is a regular expression that matches the removal criteria in your question. The s flag in front means "search and replace" the regular expression. The // means replace the regular expression with nothing. The g flag at the end means "replace all matches" if they occur more than once in a line. Finally, the -i switch means "edit the files in-place".

This solution assumes that your call IDs are all 9 digits and that the MAC address has six groups of two hexadecimal digits separated by dashes or colons.

Sign up to request clarification or add additional context in comments.

Comments

1

One way with awk (you will loose extra tabs space, every field will be separated by single space):

awk '{for(i=2;i<NF;i++) if(8>i || i>10) printf "%s ", $i; print $NF}' log

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.