- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: extracting data from string
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
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
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
08-11-2005 02:41 AM
08-11-2005 02:41 AM
Re: extracting data from string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2005 02:50 AM
08-11-2005 02:50 AM
Re: extracting data from string
Still not too clear.
But here is an other PERL variation.
This one takes the serial number desired as input variable.
If you cut & paste the perl below into a file called for example 'extract.p' then you execute as:
#perl extract.p Serial_number1 < all.data > extracted.data
Between my first example and this tweak you should have all possible needs covered (the second outputs start and stop... I'm sure you can figure out how)
My first example just execute as:
#perl extract.p < all.data
it will create: Serial_number1.tmp and Serial_number2.tmp
Good luck!
Hein
$serial = shift @ARGV or die "please provide serial number to select on";
while (<>) {
if (/^flag_start/) {
$save = 1;
$file = 0;
undef @lines;
}
if (/^flag_stop/) {
$save = 0;
push @lines, $_;
if ($file) {
print while ($_ = shift @lines );
}
print "\n";
}
push @lines, $_ if $save;
$file++ if /$serial/;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2005 03:16 AM
08-11-2005 03:16 AM
Re: extracting data from string
Thanks for your answers.
Hein, your second script seems to run .. congratulations and thanks for all.
A last question Hein, If I want to do this on all files in the same directory?
For example files starting with a patern ABC.
Thanks again
Jérôme C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2005 07:49 PM
08-11-2005 07:49 PM
Re: extracting data from string
Thanks a lot for your help.
Is it possible to extend the second perl script to pick every file in a directory starting with a common pattern and store all the results in one file?
Thanks all again
Best Regards
Jérôme
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2005 08:26 PM
08-11-2005 08:26 PM
Solutionperl extract.pl ABC*.log
It will check all the files with ABC*.log pattern.
You can also use this script as,
for file in `ls
do
perl -ne '{if(/^Serial_number1/){undef @arr;next;}if(/^flag_stop/){exit;}push @arr,$_;}END{print @arr;}' $file
done
For example:
test.log test1.log test2.log
for file in `ls test*.log`
do
perl -ne '{if(/^Serial_number1/){undef @arr;next;}if(/^flag_stop/){exit;}push @arr,$_;}END{print @arr;}' $file
done > Serial_number1.tmp
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2005 01:55 AM
08-12-2005 01:55 AM
Re: extracting data from string
I kanda had read the requirement for multiple input files, but wanted to leave somethign for you to do :-).
Muthukumar, I discarded a one liner along the lines you showed because it was my understanding that the 'serial number' was after an arbitrary number of data lines that would also be needed. So you need to start remembering at flag_start, not just when you see you are reading data for the right serial number.
Cheers,
Hein.
- « Previous
-
- 1
- 2
- Next »