- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl script to add comma if...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2004 04:05 AM
09-21-2004 04:05 AM
There is something that I still need to do with it...
Sometimes I may have a column with empty data. I need to insert a comma there. (For a deliminated file)
So after all is said and down the script produces this output...
5555642,00 0 00 18,CUSTOMER HAS
5555656,MATCHING CUTTELN
5555661,00 0 06 08,TELN NOT
I need to put an if statement after my script..
while (<>) {
chomp; # Will remove the leading , or new line
s,^\s+,,; #Remove leading spaces
my @cols=split m/\s{2,}/, $_, -1; # Split on two (or more) white space characters
print join (',',@cols)."\n";
}
That will, if 7digits (together), comma then characters, add a comma.
So the output will look like this...
5555642,00 0 00 18,CUSTOMER HAS
5555656,,MATCHING CUTTELN
5555642,00 0 00 18,CUSTOMER HAS
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2004 04:51 AM
09-21-2004 04:51 AM
Re: Perl script to add comma if...
here it is (to put before print) :
@cols=($cols[0],"",$cols[1]) if $#cols=1;
regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2004 05:16 AM
09-21-2004 05:16 AM
Solution@cols == 2 and splice @cols, 1, 0, "";
==>
while (<>) {
chomp; # Will remove the TRAILING optional new line
s/^\s+//; #Remove leading spaces
my @cols = split m/\s{2,}/, $_, -1; # Split on two (or more) white space characters
@cols == 2 and splice @cols, 1, 0, "";
print join (",", @cols), "\n";
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2004 08:00 PM
09-21-2004 08:00 PM
Re: Perl script to add comma if...
I never noticed that a 0 length in splice inserts elements... You are a living perldoc ! Are you eating a camel every morning for breakfast ? :)
Best regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2005 01:06 AM
02-23-2005 01:06 AM