one liner to search a file

Discussion in 'Perl Misc' started by h3r0, Jun 9, 2005.

  1. h3r0

    h3r0 Guest

    hi

    i need to search a file which contains the data below and extract the
    machine name only in this case 'e215c03' and overwrite the file.

    many thanks for your help.


    Name: e215c03.internal.co.uk
    Address: 10.40.10.15
    h3r0, Jun 9, 2005
    #1
    1. Advertising

  2. h3r0

    optional Guest

    #!/usr/bin/perl -w -ni.bak

    next if (! m/Name/);
    s/Name:\s*(\w+)\..*/$1/;

    print;

    You could run it as:

    % subst.pl <infile>
    optional, Jun 9, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Giles Bowkett

    nifty one-liner to search ObjectSpace?

    Giles Bowkett, Mar 6, 2007, in forum: Ruby
    Replies:
    12
    Views:
    229
    Robert Klemme
    Mar 6, 2007
  2. David Stanford

    File.delete one-liner

    David Stanford, Feb 3, 2009, in forum: Ruby
    Replies:
    8
    Views:
    119
    Joel VanderWerf
    Feb 5, 2009
  3. Larry
    Replies:
    1
    Views:
    96
    Martien Verbruggen
    Feb 3, 2005
  4. h3r0

    one liner to search a file

    h3r0, Jun 9, 2005, in forum: Perl Misc
    Replies:
    7
    Views:
    79
    Rick Measham
    Jun 13, 2005
  5. cibalo
    Replies:
    2
    Views:
    429
    J├╝rgen Exner
    Jan 14, 2012
Loading...

Share This Page