Perform a command to multiple files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Perform a command to multiple files
# 1  
Old 09-24-2003
Perform a command to multiple files

How do I perform a command to multiple files? For example, I want to look at all files in a directory and print the ones that do not contain a certain string. How do I go about doing this?
# 2  
Old 09-24-2003
............

*For example, I want to look at all files in a
*directory and print the ones that do not contain
*a certain string
for this you could use fgrep:
# fgrep string *

you can also write a litte script....

for x in *
do
<whatever>
done


so long
greetings Preßy
# 3  
Old 09-24-2003
Hi,

Do you mean that the contents of the file does match a certain string or the filename does match a certain pattern.
In case of filename it can be :

ls -l fi?e*
or
find /my/dir -type f -name t\?dr\* -exec ls -l {} \;

Else it might be :

find /my/dir -type f -name t\?dr* -exec grep <pattern> {} \;

If it's gona be too many files, use the xargs again. Many posts have explained the use of it.

Regs David
# 4  
Old 09-24-2003
I have a directory, say dir/, and I need to have a shell script that opens the dir/ then it looks at all the files in the directory and prints all of them except for the ones that have a certain string in them, "string". So, if the file contained in dir/ does not have "string" in them, then it is printed, else it is not. By saying in the file, I do not mean in the name, such as string_filename. I mean the actual contents of the file. Thanks.
# 5  
Old 09-25-2003
Sorry, but this looks like homework to me.

The above answers from me should give you a good hand-out.

Regs David
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to perform multiple operations on a number before storing to a variable?

(I am using bash) I have a command that will find the line number in a file by searching for a string where it exists. linenumber=$(grep -n "string" $FILENAME | cut -d : -fi) This returns the line number and removes the string. Now that I have the line number I want to subtract 4 from it and... (5 Replies)
Discussion started by: prodigious8
5 Replies

2. Shell Programming and Scripting

Want to login as su and perform some command

Hi All, I have some set of server and I want to write a code that can go to each server login as su and perform some command and redirect output of the command to the individual file. The command is working fine in terminal. 1. To login as su: su - username (I have privilege so it won't... (6 Replies)
Discussion started by: kotak86
6 Replies

3. Shell Programming and Scripting

loop through files in each folder and perform sed

Dear all, I have few log folders in directory (FILE) and i need to perform sed on each files inside each folders. Here is my script, and i wish to rename each file back to the same file name after modification. Can anyone guide me on my script below? eg: folder1 contain files... (2 Replies)
Discussion started by: ymeyaw
2 Replies

4. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

5. Shell Programming and Scripting

How to access files from different directories and to perform search action in those files?

Hi, I want to access files from different directories (for example: /home/dir1/file1 , /home/dir2/file2 ...) Like this i have to access these files(file1, file2...). (3 Replies)
Discussion started by: bangarukannan
3 Replies

6. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

7. Shell Programming and Scripting

Using Sed to perform multiple substitutions?

Hello I have the following output which is returned with the Month in text format instead of numerical. The output I receive is performed by using Rational Synergy CM software commands from the Unix command line and piping Unix commands on the end. bash-3.00$ ccm query -n... (4 Replies)
Discussion started by: Glyn_Mo
4 Replies

8. Shell Programming and Scripting

Need help in searching 2 files for strings then perform an action

I have 2 files. I basically want to search both of them to see if the 1st column ($1) matches and if it matches then check to see if the 2nd column ($2) matches, then execute some code showing the results of the matches. File 1: AAA 123 misc blah BBB 456 CCC 789 File 2: ... (2 Replies)
Discussion started by: streetfighter2
2 Replies

9. Shell Programming and Scripting

Splitting input files into multiple files through AWK command

Hi, I needs to split *.txt files from single directory depends on the some mutltiple input values. i have wrote the code like below for file in *.txt do grep -i -h "value1|value2" $file > $file; done. My requirment is more input values needs to be given in grep; let us say 50... (3 Replies)
Discussion started by: arund_01
3 Replies

10. AIX

Script to perform some actions on multiple files

I have this Korn script that I wrote (with some help) that is run by cron. I basically watches a file system for a specific filename to be uploaded (via FTP), checks to make sure that the file is no longer being uploaded (by checking the files size), then runs a series of other scripts. The... (2 Replies)
Discussion started by: heprox
2 Replies
Login or Register to Ask a Question