Hi,

I'm executing a command and getting the output as mentioned below. I'm redirecting this output to a file and trying the get the first column of the output and put it in a different file.

However on execution of script through Cisco Network Compliance Manager/ HP Network Automation Tool. Opened the file where output is written and found that output is in garbled format(not in line by line format).

I need to pull the first column i.e. filenames and put it in a different file in line by line format. I thought of regex and wrote it to pull the filename but not sure how to fetch the matched values from a file. Regex: (.)((A-Za-zA-Za-z0-9_*))(.*)(\.PEM|m|r|y|t)

Please guide me.

Garbled Output will somewhat look this in the file

********************************

show crypto file[] 2FAWWW-2013.PEM 1675 PEM Yes KEY Apache-Portal_2012.pem 1675 PEM Yes KEY Onlineapply-creditcards-Portal-cer 2476 PEM Yes CERT Onlineapply-creditcards-Portal-key 1675 PEM Yes KEY Onlineapply_CC_prxy_1_2013.cer 2520 PEM Yes CERT Onlineapply_CC_prxy_2013.cer 2488 PEM Yes CERT

********************************

If written in line by line format then output will be as follows

********************************

2FAWWW-2013.PEM 1675 PEM Yes KEY

Apache-Portal_2012.pem 1675 PEM Yes KEY

Onlineapply-creditcards-Portal-cer 2476 PEM Yes CERT

Onlineapply-creditcards-Portal-key 1675 PEM Yes KEY

Onlineapply_CC_prxy_1_2013.cer 2520 PEM Yes CERT

Onlineapply_CC_prxy_2013.cer 2488 PEM Yes CERT

********************************

Want to use the regex and print the filenames/column1 in different file in line by line format as below

********************************

2FAWWW-2013.PEM

Apache-Portal_2012.pem

Onlineapply-creditcards-Portal-cer

Onlineapply-creditcards-Portal-key

Onlineapply_CC_prxy_1_2013.cer

Onlineapply_CC_prxy_2013.cer

********************************

Code used in NCM/HPNA Tool

#!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Opsware::NAS::Connect; my($host,$port,$user,$pass) = ('localhost','$tc_proxy_telnet_port$','$ +tc_user_username$','$tc_user_password$'); my $device = '#$tc_device_id$'; my @output; my $con = Opsware::NAS::Connect->new(-user => $user, -pass => $pass, - +host => $host, -port => $port); $con->login(); $con->connect( $device ) or die "Failed to connect."; $con->cmd("terminal length 0"); print "show crypto files \n"; open my $fh, ">cryptofiles.log" or die "Cant open file died unexpected +ly"; @output = $con->cmd("show crypto files"); foreach (@output) { print $fh $_; } close $fh; $con->disconnect(); $con->logout(); undef $con; exit(0);

Thanks!


In reply to Fetch the regex matched values from file and write it to a file in line by line format.(Using HPNA to execute the script) by bks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.