Remove entire line from a file if 1st column matches a pattern

I have one requirement to delete all lines from a file if it matches below scenario. File contains three column. Employee Number, Employee Name and Employee ID

Scenario is: delete all line if Employee Number (1st column) contains below

  1. Non-numeric Employee Number
  2. Employee Number that are over 99999 (data length is over 5 characters)
  3. Employee Number that have any alpha characters

At present my file looks like as below

0000-|John T|johnT
4906790742|amit kumar|akumar
SM36950SE2|Mike henry|mhenry1
03942|ronald F|ronaldf
36152|anshu ran|aran2
C0490|micheal z|michael3

I want my file should look like

03942|ronald F|ronaldf
36152|anshu ran|aran2

I need your assistance and guidance on this.

I suggest to read the man page of sed , especially the part about "one-address-commands".

I hope this helps.

bakunin

Hello Anshu Rajan,

Kindly use code tags for commands/inputs/codes used in your posts in spite of HTML codes. Could you please try following and let me know if that helps.

awk -F"|" -vvar=5 '{if($1 !~ /[[:alpha:]]/ && $1 !~ /[[:punct:]]/ && length($1) <= var){print}}'  Input_file

Output will be as follows.

03942|ronald F|ronaldf
36152|anshu ran|aran2

Thanks,
R. Singh

Thanks Ravinder, It worked exactly what I needed. Thanks a lot