[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Basic Question




thank you, and i really appreciate the code, but i have some problems.
supposing that my samp.txt file has this content
one 0:0:0 1999
	two
	three
	four
	five

six 0:0:0 1999
	seven
	eight
	nine
	ten

In your script how do i mitigate the space to produce these output

one:0:0:0:1999:two:three:four:five
six:0:0:0:1999:seven:eight:nine:ten

thank you again.

> 
> 	If you mean to convert a file from one word per line to several
> words per line separated by colons, the following perl script will work:
> 
> ------------------------------------
> #!/usr/bin/perl -w
> 
> print "Enter name of output file:  ";
> chop($outfile=<STDIN>);
> open(OUTFILE,">$outfile") || die "Could not open $outfile for writing";
> 
> while (<>) {
>     chop;
>     push (@array,$_);
> }
> 
> $out=join(':', @array);
> $out =~ s/::/\n/;
> $out =~ s/:$/\n/;
> 
> print OUTFILE $out;
> ------------------------------
> 
> I'm far from an expert on perl, so I'm sure someone could come up with a
> shorter version.
> 
> 	Assuming you have perl on your system, save the above code as (for
> example) myscript.pl, and run 
> 
> 	perl myscript.pl sample.txt
> 
> The script will prompt you for the name of the file to write to.
> 
> 	Hope this helps.
> 
> Jamie Kufrovich
> 
> Egg, eggie sunlink net
> FMSp3a/MS3a A- C D H+ M+ P+++ R+ T W Z+ 
> Sp++/p# RLCT a+ cl++ d? e++ f h* i+ j p+ sm+
> 
> 
> -- 
>   PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
> 		http://www.redhat.com http://archive.redhat.com
>          To unsubscribe: mail redhat-install-list-request redhat com with 
>                        "unsubscribe" as the Subject.
> 
> 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]