Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Match line of File

Status
Not open for further replies.

klmc

Programmer
Nov 14, 2003
18
US
I am writing a script that will take a file and add a '/' at the end of the line if the line begins with '16' and it currently doesn't have a '/' at the end. I can get it to find the lines that start with 16, but it adds a second '/' even if the line already ends in one. I am writing this on a Windows 2000 pc. Here is what I have so far:

Code:
open(BANK, "<Wac 5-3-04.wcr") or die "Can't open bank input.\n";

@B = <BANK>;
  while($Bank = shift(@B)) 
  {chomp ($Bank);
  {if  (($Bank =~m/^16/) && ($Bank !=~m/\/$/)){
  print "$Bank/\n";
}
else
{print "$Bank\n";
}
}
}

My input file is currently like this:

Code:
16,475,19504,Z,118,78,CHECK
16,575,1207,Z,0000,,TRANSFER  TO   LA MAD OF
16,255,58,S,58,000,000,118,,CHECK REVERSAL
16,275,855,S,855,000,000,00,/
88,TRANSFER FROM  LA MAD OF

and I would need the file to look like this:

Code:
16,475,194,Z,1500,78,CHECK/
16,575,127,Z,0000,,TRANSFER  TO  LA MAD OF/
16,255,580,S,580,000,000,118,,CHECK REVERSAL/
16,275,85,S,85,000,000,000,/
88,TRANSFER FROM LA MAD OF

Any suggestions would be greatly appreciated.

Thanks.
 
You have a typo. Your second condition:
Code:
$Bank !=~m/\/$/
Should be:
Code:
$Bank !~m/\/$/

The opposite of =~ is !~.

I tried this without the typo and it seemed to work.

--G
 
Must have been staring at it too long and didn't see it. Thanks so much for your help. I appreciate it.
 
should really use substr if you know the absolute position of an exact string


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top