HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- PERL - pattern extraction help
Operating System - Linux
1828793
Members
2627
Online
109985
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
10-11-2007 07:17 PM
10-11-2007 07:17 PM
PERL - pattern extraction help
I have got a file that has patterns similar to the sample provided below
C\WINDOWS\system\hpsysdrv.exe
C\hp\KBD\kbd.exe
C\Program Files\iTunes\iTunesHelper.exe
C\WINDOWS\system32\VTTimer.exe
C\WINDOWS\ALCXMNTR.EXE
C\Program Files\EarthLink TotalAccess\TaskPanl.exe
C\Program Files\iPod\bin\iPodService.exe
C\WINDOWS\system32\ctfmon.exe
C\Program Files\Compaq Connections\1940576\Program\BackWeb-1940576.exe
C\Program Files\NETGEAR\WPN311\wlancfg5.exe
D\OCSetup.exe
C\Program Files\Microsoft Windows OneCare Live\Staging\SEA3\ocsetup.exe
I am trying to write a PERL script that would extract only the .exe content from the file like ocsetup.exe, ctfmon.exe etc.
Can anyone please help.
Thanks,
Anand
C\WINDOWS\system\hpsysdrv.exe
C\hp\KBD\kbd.exe
C\Program Files\iTunes\iTunesHelper.exe
C\WINDOWS\system32\VTTimer.exe
C\WINDOWS\ALCXMNTR.EXE
C\Program Files\EarthLink TotalAccess\TaskPanl.exe
C\Program Files\iPod\bin\iPodService.exe
C\WINDOWS\system32\ctfmon.exe
C\Program Files\Compaq Connections\1940576\Program\BackWeb-1940576.exe
C\Program Files\NETGEAR\WPN311\wlancfg5.exe
D\OCSetup.exe
C\Program Files\Microsoft Windows OneCare Live\Staging\SEA3\ocsetup.exe
I am trying to write a PERL script that would extract only the .exe content from the file like ocsetup.exe, ctfmon.exe etc.
Can anyone please help.
Thanks,
Anand
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2007 08:02 PM
10-11-2007 08:02 PM
Re: PERL - pattern extraction help
> perl -nle'm{([^/\\]+\.exe)\b}i and print $1' xx.dta
hpsysdrv.exe
kbd.exe
iTunesHelper.exe
VTTimer.exe
ALCXMNTR.EXE
TaskPanl.exe
iPodService.exe
ctfmon.exe
BackWeb-1940576.exe
wlancfg5.exe
OCSetup.exe
ocsetup.exe
Enjoy, Have FUN! H.Merijn
hpsysdrv.exe
kbd.exe
iTunesHelper.exe
VTTimer.exe
ALCXMNTR.EXE
TaskPanl.exe
iPodService.exe
ctfmon.exe
BackWeb-1940576.exe
wlancfg5.exe
OCSetup.exe
ocsetup.exe
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2007 12:00 AM
10-12-2007 12:00 AM
Re: PERL - pattern extraction help
Merijn knows perl. Heed his advice!
His code matches and remenbers a piece of string on the line startign with a backslash and ending in .exe.
If there is seperate text beyond the .exe, then it is ignored, whcih you probably want.
Is every image ganartueed to be called .exe or could there be a .exe_v3 or such?
Are there arguments beyond the image?
Will every line have an image, and a \ before the image name?
If the last is true, and other simple approach could be:
perl -pe "s/^.*\\//" test.txt
Here we replace be beginning of every line up the the last backslash with nothing (the .* is 'greedy').
Or if there are other lines in the mix:
$ perl -ne "s/^.*\\//; print if /.exe/" test.txt
Enjoy!
Hein.
His code matches and remenbers a piece of string on the line startign with a backslash and ending in .exe.
If there is seperate text beyond the .exe, then it is ignored, whcih you probably want.
Is every image ganartueed to be called .exe or could there be a .exe_v3 or such?
Are there arguments beyond the image?
Will every line have an image, and a \ before the image name?
If the last is true, and other simple approach could be:
perl -pe "s/^.*\\//" test.txt
Here we replace be beginning of every line up the the last backslash with nothing (the .* is 'greedy').
Or if there are other lines in the mix:
$ perl -ne "s/^.*\\//; print if /.exe/" test.txt
Enjoy!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2007 12:08 AM
10-12-2007 12:08 AM
Re: PERL - pattern extraction help
> His code matches and remenbers a piece of string on the line startign with a backslash and ending in .exe.
No, it does not. It matches any sequence of characters that do NOT match a forward or backward slash, followed by a .exe extension and a (zero-width) word boundary, all case-insensitive.
Essentially, this drops of the path part on both dos and unix.
The weakness in this match is files like D:foo.exe, which will match including the D:, as there is no slash at all and colon's are valid in file names.
I wrote the regex like that to allow whitespace in file names
If there is seperate text beyond the .exe, then it is ignored, whcih you probably want.
Enjoy, Have FUN! H.Merijn
No, it does not. It matches any sequence of characters that do NOT match a forward or backward slash, followed by a .exe extension and a (zero-width) word boundary, all case-insensitive.
Essentially, this drops of the path part on both dos and unix.
The weakness in this match is files like D:foo.exe, which will match including the D:, as there is no slash at all and colon's are valid in file names.
I wrote the regex like that to allow whitespace in file names
If there is seperate text beyond the .exe, then it is ignored, whcih you probably want.
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP