From: Rakesh Sharma on
On Nov 27, 8:57 pm, "John W. Krahn" <some...(a)example.com> wrote:
> Rakesh Sharma wrote:
> > On Nov 26, 12:25 am, Sashi <small...(a)gmail.com> wrote:
> >> Hi all, I have a bunch of *.csv files. These are comma separated
> >> values. I'd like to replace the first field with the file name, minus
> >> the .csv extension.
> >> For example, my_file.csv has the following fields:
> >> 1,2,3,4
> >> 5,6,7,8
>
> >> I'd like to edit the file to be
> >> my_file, 2, 3,4
> >> my_file, 6,7,8
>
> >> Any ideas?
> >> Thanks,
> >> Sashi
>
> > perl -F, -i.bak -MFile::basename -lpe '$_ = join",",basename($ARGV),@F
> > [1..$#F]'  myfile1.csv myfile2 .csv ........
>
> -MFile::basename should be -MFile::Basename, but basename() does not
> remove the file name extension.
>
> Without the -a option the @F array will be empty.
>
> John
> --
> The programmer is fighting against the two most
> destructive forces in the universe: entropy and
> human stupidity.               -- Damian Conway- Hide quoted text -
>
> - Show quoted text -

Thanks for pointing that out!

perl -MFile::Basename -F',' -i.BAK -pale '
$_ = join",", basename($ARGV, ".csv"), @F[1..$#F];
' my_file1.csv my_file2.csv ...