Applying python on all the files in one folder --UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Applying python on all the files in one folder --UNIX
# 1  
Old 04-09-2014
Applying python on all the files in one folder --UNIX

Dear all,
I know this might be a simple and silly question but I am struggling with it
I have a long unix script and in a section of if I want to use a python script which should select all the files and run the script on it (as a whole)
the loop I have is selecting file by file and I dont know how to make is select all the files in the each folder
my loop for now looks like
Code:
mkdir result/$doc/02-data
FILES="result/${doc}/01-data/*"
for X in $FILES
do
	name=$(basename $X) 
	cat *| python compare.py > result/${doc}/02-data/${name}		
done

thank you in advance for your help
A-V
# 2  
Old 04-09-2014
Your script appears to have issues to em.

What follows is what your script does, which is probably not what you intended.

Code:
mkdir result/$doc/02-data                
      -> create a new empty directory in the current directory
FILES="result/${doc}/01-data/*"    
-> FILES is a variable with a list of all  files in whatever the variable doc points to
for X in $FILES
-> loop thru each file in FILES

do
	name=$(basename $X) 
-> the filename without a directory for each filename in FILES
	cat *| python compare.py > result/${doc}/02-data/${name}		
-> Pipe content of  all files in the current directory into a python script
---> redirect the python output to the file with current value of name and doc
done

The script does not make sense to me. Please tell us what you are trying to do -NOT what you think your script should look like.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 04-09-2014
I have a folder that has one main.csv and few other files (files1.txt, file2.txt, ...)
my python compares the main against the rest of the files
so i need to select an entire folder and not individual files...
I want to learn how it is possible to select all the files in one folder

Last edited by A-V; 04-09-2014 at 09:16 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

HP-UNIX How to zip/compress files in a folder?

Environment: HP-Unix Operating System B.11.31 U ia64 I have a folder with around 2000 files. There are some files which sizes are more than 8 GB. I need to compress all the files in the folder into a single file, so that I can transfer the file. I tried with tar command, but the tar... (8 Replies)
Discussion started by: Siva SQL
8 Replies

2. Solaris

Need to transfer files between 2 UNIX servers, with same folder permission

I need to transfer directories/files between 2 Unix servers, with same folder permission. I tried scp, but it retains the the permissions, but changes the owner of the directory/file to the user used to copy them to the destination. I don't want that to happen. If possible without any other... (6 Replies)
Discussion started by: Pandee
6 Replies

3. UNIX for Dummies Questions & Answers

applying unix command in EBCIDIC file

Hi, I'm having a general query. If we do cat <file name> on a Ebcidic format file then many unknown characters are displayed in my screen. Can we change the character set related to EBCIDIC in session level and apply the cat command on a EBCIDIC file? By doing so can we able to see the... (2 Replies)
Discussion started by: poova
2 Replies

4. UNIX and Linux Applications

Move Files From One Folder To Another In UNIX

There are around 13 files in folder1.I need to move these files to another folder folder2,one file at a time, after checking whether a file exists in another folder folder3. If a file exists in folder3, we should not move files from folder1 to folder2. If there are no files in folder3, we need... (1 Reply)
Discussion started by: Jassz
1 Replies

5. UNIX for Advanced & Expert Users

UNIX: Command to compress folder and all files into a tar

I am trying to grab a folder and all the folders and files underneath it and send it from one computer to another. I basically want to compress the whole folder into a tar, tgz, or zip file so that it can be sent as one file. is there a command to compress a folder and all its contents into a tar... (7 Replies)
Discussion started by: kane4355
7 Replies

6. Shell Programming and Scripting

Applying lock on a file in Unix Ksh

Hi, How can we apply lock on a text file through Unix Ksh script. I did found a command flock (file descriptor) but am not very acquainted with the usage. Can anybody tell me if I need to use Flock command for applying locks to a file while writing on it. If the person can explain the usage... (3 Replies)
Discussion started by: kum5256
3 Replies

7. UNIX for Dummies Questions & Answers

unix command to cound the number of files in a folder

Hi All Can some one help me out. Please tell the unix command to cound the number of files in a folder. Ungent please# Thanks manas (6 Replies)
Discussion started by: manas6
6 Replies

8. Programming

unix C++: get the files from a folder

Hello everybody! How can I get the list of files from a folder in C++ (unix)? thanks in advance for any help! regards (2 Replies)
Discussion started by: nadiamihu
2 Replies

9. UNIX for Dummies Questions & Answers

Viewing files of another unix server (in a folder)

I think that's what I'm trying to do. This is the problem: I log onto my comp, Comp1. Then, from the terminal, since my web server is on another comp, I type: xrlogin Comp2, so I log on to that computer. I then navigate to my directory by typing: cd /domain/myDir, so I am in my directory, on the... (3 Replies)
Discussion started by: Djaunl
3 Replies

10. Shell Programming and Scripting

How can i move data files from a server to unix folder

Hi: I am very new in UNIX environment. I need big help. How I can move data files from a server to UNIX folder by script. I don't want to use ws-ftp. The script should check the file on server, if any file found, move it to UNIX folder. I will be very happy, if some one helps me out.... (1 Reply)
Discussion started by: shah2
1 Replies
Login or Register to Ask a Question