![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to split special characters "|" using awk | krishna9 | Shell Programming and Scripting | 3 | 05-22-2008 06:30 AM |
| perl split funciton - special character "/" | deepakwins | UNIX for Dummies Questions & Answers | 5 | 02-08-2008 12:19 AM |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 03:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| split the string "Setview: arv-temp-view" | amitrajvarma | Shell Programming and Scripting | 2 | 10-11-2007 05:14 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Perl - split with "|"
Hi,
I’m having some troubles with the split-command. My file is formatted like this: field1 | field2 | field3 | field4 | … The purpose is to catch for example the first and fourth field so I’m using “|” as delimiter, but the thing is that he then only takes the first character out of the field. So for example when I have the following: abc | def | ghi | jkl | … With the script below I’m getting: a b c d in stead of abc def ghi jkl Now if for instance I use “#” as delimiter I get the correct output. So now I’m wondering why he doesn’t execute the split correctly with the “|” delimiter? Code:
#!/usr/bin/perl
opendir(DIR,".");
@contents = readdir(DIR);
closedir(DIR);
foreach $file (@contents)
{
if ($file =~ m/test.txt/)
{
open(FILE,$file);
while($line = <FILE>)
{
chomp($line);
(@params) = split('|',$line);
foreach $p (@params)
{
print "$p\n";
}
}
}
}
|
|
||||
|
Code:
#!/usr/bin/perl
opendir(DIR,".");
@contents = readdir(DIR);
closedir(DIR);
foreach $file (@contents)
{
if ($file =~ m/test.txt/)
{
open(FILE,$file);
while($line = <FILE>)
{
chomp($line);
(@params) = split(/\|/,$line);
foreach $p (@params)
{
print "$p\n";
}
}
}
}
|
|
||||
|
Thx, it works fine now.
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| delimited, perl split |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|