help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] copy files w


From: Val Krem
Subject: Re: [Help-bash] copy files w
Date: Thu, 25 May 2017 20:25:25 +0000 (UTC)

Hi Chris and all,


I am trying to modify this script to do it recursively. I want to   go in  all 
sub folders and copy the files and here is my attempt

find . -type f -name *.txt | for file in *.txt

  do
       cp "$file" "${file/.txt/_new.txt}"
 done

But it only do the job in the current directory.


Thank you







On Saturday, April 29, 2017 8:08 PM, Chris F.A. Johnson <address@hidden> wrote:



On Sun, 30 Apr 2017, Val Krem wrote:

> Hi all,
>
> I have several files with the same  extension name(*.txt). I want to have   
> copy of these files by attaching a suffix to each of the files. Example 
> test1.txt should be copied to test1_new.txt. The suffix to be added in all 
> files is the same. I tried using this but did not work.
>
> ls *.txt | xargs -I {} cp {} {}_new.txt
>
> test.txt should be test_new.txt
> but I got test.txt_new.txt
>
> what should I do to make work?

for file in *.txt

do
   cp "$file" "${file/.txt/_new.txt}"
done

-- 
Chris F.A. Johnson, <http://cfajohnson.com
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]