Hi All,
I have a file with 3 columns (Bank Name, Account Number and Amount). My requirement, I need to delete lines using Unix Shell script:
- Which are having Alphanumeric characters in Account Number (eg. Line3).
- Which are having 0.00 in amount. (eg. Line4)
- And also I need to delete the text "End Of File".
Sample Data:-
--------------
Bank1,123,100.00
Bank2,456,200.00
Bank3,A789,300.00
Bank4,1011,0.00
End of File
awk -F, '{f=($NF!="0.00" && $2 !~ /[a-zA-Z]/ && $0!~ /End of File/)?1:0}f' file
Use the following code
while read line
do
sed '/.*,[A-Za-z]/d' <<< $line | sed '/^End of File/d' | sed '/.*,0\.00/d'
done < input > output
Now the output file will contain only the following lines
Bank1,123,100.00
Bank2,456,200.00
# cat erasefile
Bank1,123,100.00
Bank2,456,200.00
Bank3,A789,300.00
Bank4,1011,0.00
End of File
# sed -e '/.*[A-Z][0-9].*/d
/,0.00*$/d
/End of File/d' erasefile
Bank1,123,100.00
Bank2,456,200.00
As a matter of form I'll post a perl variant:
#!/usr/bin/perl
my $input='bankdata' ;
open(INPUT, "$input") or die "Error opening file: $!\n" ;
while (<INPUT>) {
chomp $_;
@arrr = split(/,/);
if ($arrr[0] !~ /^End of File/ ) {
if ($arrr[1] !~ /[A-Z]/) {
if ($arrr[2] !~ /^0.00/) {
print ("$_\n");
}
}
}
else {
next ;
}
}
close(INPUT);