Hello everyone, I am trying to replace whitespaces, from my input file, with commas. The challenge I am currently experiencing is that when a selection of the line has no characters it is not recognizing the selection therefore not adding the extra comma in place of the line. What I want my script to do is, add the comma regardless if there is or isn't characters present in the section of the line. Below is what I currently have, where I'm stating that every 3 whitespaces in my input file per line, replace with a comma. Thank you for your time and help, as always everyone is very helpful on here.
use strict; use warnings; open (NEW, ">", "OUTPUT_COMMA.txt" ) or die "could not open:$!"; open (FILE, "<", "INPUT.txt") or die "could not open:$!"; while (my $line = <FILE>) { $line =~s/\s{3} +/,/g; print NEW $line; } close (FILE); close (NEW)
INPUT File:
12345 DOE,JOHN $50.00 REFUND COMPLETE 12345 DOE,JOHN $25.00 DENIED COMPLETE 12345 DOE,JOHN $75.00 COMPLETE 12345 DOE,JOHN $10.00 REFUND COMPLETE
EXPECTED OUTPUT File:
12345,DOE,JOHN,$50.00,REFUND,COMPLETE 12345,DOE,JOHN,$25.00,DENIED,COMPLETE 12345,DOE,JOHN,$75.00,,COMPLETE 12345,DOE,JOHN,$10.00,REFUND,COMPLETE
CURRENT OUTPUT File:
12345,DOE,JOHN,$50.00,REFUND,COMPLETE 12345,DOE,JOHN,$25.00,DENIED,COMPLETE 12345,DOE,JOHN,$75.00,COMPLETE 12345,DOE,JOHN,$10.00,REFUND,COMPLETE
In reply to Replace Whitespace with Comma by jlope043
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |