For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > June 2005 > one liner to search a file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author one liner to search a file
h3r0

2005-06-09, 3:57 pm

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

optional

2005-06-09, 3:57 pm

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

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

print;

You could run it as:

% subst.pl <infile>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com