Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > one liner to search a file

Reply
Thread Tools

one liner to search a file

 
 
h3r0
Guest
Posts: n/a
 
      06-09-2005
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

 
Reply With Quote
 
 
 
 
optional
Guest
Posts: n/a
 
      06-09-2005
#!/usr/bin/perl -w -ni.bak

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

print;

You could run it as:

% subst.pl <infile>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiline Search-Replace With Perl One-liner cibalo Perl Misc 2 01-14-2012 06:24 AM
File.delete one-liner David Stanford Ruby 8 02-05-2009 10:06 PM
nifty one-liner to search ObjectSpace? Giles Bowkett Ruby 12 03-06-2007 08:24 AM
one liner to search a file h3r0 Perl Misc 7 06-13-2005 12:40 AM
one-liner to make all programs one-liners Larry Perl Misc 1 02-03-2005 11:35 PM



Advertisments