Thursday, February 3, 2022

[SOLVED] How to remove unix timestamp specific data from a flatfile

Issue

I have a huge file containing a list like this

[email protected]^B1569521698
[email protected],@2domain.com^B1569521798
[email protected],[email protected]^B1569521898
[email protected]^B1569521998
..
..

The file is named /usr/local/email/whitelist

The number after ^B is a unix timestamp

I need to remove from the list all the rows having a timestamp smaller than (e.g.) 1569521898.

I tried using various awk/sed combinations with no result.


Solution

Since you have control characters in your Input_file could you please try following once. This is written and tested with given samples only.

awk '
match($0,/\002[0-9]+/){
  val=substr($0,RSTART+1,RLENGTH-1)
  if(val>=1569521898){ print }
  val=""
}
'  Input_file


Answered By - RavinderSingh13
Answer Checked By - Robin (WPSolving Admin)