Link to home
Start Free TrialLog in
Avatar of xbox360dp
xbox360dp

asked on

Perl Script - Remove row of data based on column value

Gurus,

I need a perl script that will delete a row or rows of data based a column value.

Example
File1.txt - Before
Data1|00|123
Data2|11|456
Data3|10|789

Example
File1.txt - After
Data2|11|456
Data3|10|789

So delete from file where column 2 equals "00"

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
File1.txt - Before
Data1|00|123
Data2|11|456
Data3|10|789

perl -F'\|' -i.bak -ane 'print "$F[0]|$F[1]|$F[2]" unless $F[1] =~ /^00$/' File1.txt

File1.txt - After
Data2|11|456
Data3|10|789

File1.txt.bak - Backup File
Data1|00|123
Data2|11|456
Data3|10|789