- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Perl - Simple field delimeter based extraction
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
Discussions
Discussions
Discussions
Forums
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
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
тАО07-31-2005 12:20 PM
тАО07-31-2005 12:20 PM
The line might look like:
field number one|field number two|field 3 etc.
I am assuming that this can be done with a simple expression... as opposed to breaking up the string using tokens but my mind is blank as to how this may look syntax wise at the moment.
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2005 06:36 PM
тАО07-31-2005 06:36 PM
Solutionmy %keys;
open my $key_file, "
chomp;
# assuming the key is the first field
my ($key, @fields) = split m/\|/, $_, -1;
$keys{$key} = [ @fields ];
# alternatively, if you don't need the other
# fields, and field 5 is your key
$keys{(split /\|/, $_, -1)[4]}++;
}
close $key_file;
# Now parse the other file(s)
while (<>) {
my @fields = split m/\|/, $_, -1;
# See if field 3 (1-based, perl is 0-based)
# exists in your keys
exists $key{$fields[2]} or next;
# line accepted, process
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2005 06:42 PM
тАО07-31-2005 06:42 PM
Re: Perl - Simple field delimeter based extraction
echo "hi|bye|see|you" | perl -ne '@keys=split(/\|/); print @keys;'
Use @keys to grep the line in a file.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2005 06:52 PM
тАО07-31-2005 06:52 PM
Re: Perl - Simple field delimeter based extraction
#!/usr/bin/perl
# single Line
$_="first|second|third|four|fifth";
@keys=split (/\|/);
$FILE="/tmp/test.log";
open(FH,$FILE) || die "Can not open file: $!";
while (
foreach $key (@keys)
{
print $_ if ( m/$key/);
}
}
# end #
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2005 11:54 AM
тАО08-01-2005 11:54 AM
Re: Perl - Simple field delimeter based extraction
All these work and work remarkably well.
I will assign points after I have coded and tested based on what I have learned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2005 05:32 PM
тАО08-02-2005 05:32 PM
Re: Perl - Simple field delimeter based extraction
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2005 05:33 PM
тАО08-02-2005 05:33 PM