copying with a certain extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copying with a certain extension
# 1  
Old 10-27-2011
copying with a certain extension

trying to copy all the files without extension then add
"*.txt" but its not working is there any other way and i do not want to use
cpio -vdump just want to use copy command

Code:
FROM=/usr/share/doc
TO=/aleza/doc
#the follow function copies all the files without extensions
call(){

cd $FROM
find . ! -name "*.*" -type f | cpio -vdump /swepa/doc

}

#this func add the "*.txt" extension 
me(){

cd $TO
for i in * ; do
	        echo mv \"$i\" \"$i.txt\" | sh
	done

}
call
me

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.
# 2  
Old 10-27-2011
Try
Code:
find . "!" -name "*.*" -type f -exec cp {} "$TO"/{}.txt \;

# 3  
Old 10-27-2011
why have u used -exec?
# 4  
Old 10-27-2011
Or a move verbose one (like Carlo's):
Code:
find . \! -name "*.*" -type f | xargs -t -I {} cp "{}" "${TO}/{}.txt"

The difference is that it will print all cp commands executed! =o)

E.g.
Code:
# TO="./output"
# find . \! -name "*.*" -type f | xargs -t -I {} cp "{}" "${TO}/{}.txt"
cp ./2 ./output/./2.txt
cp ./1 ./output/./1.txt
cp ./3 ./output/./3.txt
cp ./4 ./output/./4.txt
# ls -lrt ./output/
total 0
-rw-rw-r--  1 jboss jboss 0 Oct 27 15:10 4.txt
-rw-rw-r--  1 jboss jboss 0 Oct 27 15:10 3.txt
-rw-rw-r--  1 jboss jboss 0 Oct 27 15:10 2.txt
-rw-rw-r--  1 jboss jboss 0 Oct 27 15:10 1.txt

As you can see, find will also print the path to the file in the output. To "solve" this, you can use the -printf option, but there is a problem, depending on your OS, this option will not be available:
Code:
# -printf arguments
# %h -> Path to the file
# %f -> Filename
find . \! -name "*.*" -type f -printf "cp %h/%f ${TO}/%f.txt\n" | sh


Last edited by felipe.vinturin; 10-27-2011 at 02:20 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying multiple files and appending time stamp before file extension

Hi, I have multiple files that read: Asa.txt Bad.txt Gnu.txt And I want to rename them using awk to Asa_ddmmyytt.txt and so on ... If there is a single command or more efficient executable please share! Thanks! (4 Replies)
Discussion started by: Jesshelle David
4 Replies

2. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

3. UNIX for Dummies Questions & Answers

copying files of certain extension?

Hi, I am using scp to copy a certain directory over the network. This folder contain some files that I am not interested in. My question is; is it possible to copy files of certain extension only, keeping the same directory hierarchy as it is (that is sub-folders)? Thanks (8 Replies)
Discussion started by: faizlo
8 Replies

4. Shell Programming and Scripting

Getting the file extension

I have a file n06-z30-sr65-rgdt0p25-varp0.25-8x6drw-test.cmod and I want to get the extension. At the moment I have set filextension = `echo $f | awk 'BEGIN {FS="."} {print $2}'` which of course does not work as there is a point in varp0.25 (13 Replies)
Discussion started by: kristinu
13 Replies

5. Shell Programming and Scripting

Look for more then one extension.

I am currently scanning a directory with a shell script to look for all files with a .sh extension. I am wondering how to make it look for more then one extension. For example all .sh, .conf, and .sql files? Currently this is what I am doing.... find... (3 Replies)
Discussion started by: LRoberts
3 Replies

6. Linux

copying all files except those with certain extension

Hi, I have a root directory which has a big number of other subdirectories and contains a big number of files. I want to copy all these files and directories to another folder except files with certain extension, say .txt, files - how may I do this? Thanks, faizlo (8 Replies)
Discussion started by: faizlo
8 Replies

7. UNIX for Dummies Questions & Answers

extension problem please help

I am executing a program wp1s0000.sh_old and it is executing as expected irrespective of the extension "sh_old" how is this possible ?? (1 Reply)
Discussion started by: sharmasdeepti
1 Replies

8. UNIX for Dummies Questions & Answers

without extension

Hi, I need a help regarding a small requirement. I have a list of C files. I need to put them in a file but without .c extension. say if I have the files as file01.c, file02.c, file03.c etc My file say cfiles should have file01 file02 file03 ... ... etc Appreciate your quick help on... (3 Replies)
Discussion started by: adurga
3 Replies

9. Shell Programming and Scripting

Append extension

Can anyone tell me the easiest way to append an extension (ie. .ldr) to all files in a directory that do NOT have an extension? The directory contains files with and without extensions, however I'm only interested in the files with NO extension. Thanks. (3 Replies)
Discussion started by: here2learn
3 Replies

10. Shell Programming and Scripting

how do i change extension

Hi I am writing a script which does an FTP of a set of files onto another machine and then would have to rename the files into a different extension on the source machine. for example if the file being sent via FTP is sample.txt. Once the file has been transferred i would want to modify the... (2 Replies)
Discussion started by: kswaraj
2 Replies
Login or Register to Ask a Question