Hi!
This should solve the problem. Save following lines as some_name.pl Also mention file name in the file as mentioned.
#!/usr/bin/perl
open(vp,"myfile"); #myfile is the file in the same dir or u can specify full path here eg: /home/my/myfile
foreach $names (<vp>){ #Th following lines by Devdas Bhagat @names = split(' ',$names); #Split the line on whitespace #and assign to the array @names
foreach (@names) { #For all values in the array print "$_ " #Print the value followed by a single # space if ! /@/; #Iff there was no '@' in it. } print "\n"; #Print a newline }
Run the file as perl some_name.pl You can redirect its output to file as perl some_name.pl > names.txt
Regards swanand techieinfo.cjb.net
Message: 4 Date: Tue, 16 Dec 2003 15:06:56 +0530 From: Devdas Bhagat devdas@dvb.homelinux.org Subject: Re: [ILUG-BOM] regexp query To: Devdas Bhagat devdas@dvb.homelinux.org, "GNU/Linux Users Group, Mumbai, India" linuxers@mm.ilug-bom.org.in Message-ID: 20031216150656.A2895@evita.devdas.geek Content-Type: text/plain; charset=us-ascii
On 11/12/03 09:52 +0530, Devdas Bhagat wrote:
On 10/12/03 18:00 +0530, Dr. Sharukh K. R. Pavri. wrote:
I have a text file in the format
Full name email@ddress
perl -e 'while(<>) { @names = split /\s+/; foreach (@names) { print "$_
" if ! /@/)}; print "\n" } ' < file. Replying to myself:
The above one liner is equivalent to: #!/usr/bin/perl
while (<STDIN>) { #read one line from standard input @names = split /\s+/; #Split the line on whitespace #and assign to the array @names
foreach (@names) { #For all values in the array print "$_ " #Print the value followed by a single # space if ! /@/; #Iff there was no '@' in it. } print "\n"; #Print a newline }
I redirect standard input from the file 'file' via the shell operator <.
Devdas Bhagat
_________________________________________________________________ Worried about inbox overload? Get MSN Extra Storage now! http://join.msn.com/?PAGE=features/es
On 17/12/03 08:01 +0000, swanand pathak wrote:
Hi!
This should solve the problem. Save following lines as some_name.pl
If we are scripting.
Also mention file name in the file as mentioned.
#!/usr/bin/perl
No -w?
open(vp,"myfile");
Wheres the die?
#!/usr/bin/perl -w use strict;
my $file = "/path/to/users/file"; open(ADDRBK, "<", $file) or die "Failed to open $file: $!";
while (<ADDRBK>) { my @names = split(/\s+/, $_); foreach my $name (@names) { print "$name " if $name !~ /@/; } print "\n"; }
<eot, going from a one liner to a whole script> Devdas Bhagat