How do you check for a particular string in 1000's of files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do you check for a particular string in 1000's of files?
# 1  
Old 09-25-2012
Question How do you check for a particular string in 1000's of files?

Please forgive my ignorance on scripting. I am trying to determine (via a script) if a certain string of characters is present . The string that I am looking for is a constant length.

Here is the string I am searching for:
Code:
Model_Type={t}, ModelName={m}

I need to determine if the above string comes after this string at the beginning of the file:

Code:
{d "%w- %d %m-, %Y - %T"}

So, in summary, I need to check 1000's of files for this exact match:

Code:
{d "%w- %d %m-, %Y - %T"} Model_Type={t}, ModelName={m}

And then once I find a file that does NOT match the above I need to ADD the Model_Type line after the timestamp.

I'm wondering if there is also a way to keep a log as to what files where changed with a datestamp of when the script ran looking for the Model_Type string.

Last edited by Corona688; 09-25-2012 at 12:51 PM..
# 2  
Old 09-25-2012
could you please post some records of your file.
Is Model_Type value needs to be passed as parameter ?
# 3  
Old 09-25-2012
try:
This gives you a list of files to work on:
Code:
cd /path/to/many/files
for fname in *
do 
  grep -qF  '{d "%w- %d %m-, %Y - %T"} Model_Type={t}, ModelName={m}' $fname
  if [ $? -ne 0 ] ; then
     echo $fname
  fi
done > /tmp/files.lis

For the next step we need sample input and expected output. We can apply the data in files.lis to do the work.
This User Gave Thanks to jim mcnamara For This Post:
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 check in a folder all files which doesnt have the specifc string?

I have a folder with 100s of dat files, with delimiter "|", in some files they didn't provide this delimiter. how to automatically check those list of files in a folder which doesnt have a delimiter or string this way "|" is it possible? Thank you very much for the helpful info. (3 Replies)
Discussion started by: cplusplus1
3 Replies

2. Shell Programming and Scripting

Creating a sequence of numbers in a line for 1000 files

Hi, I try to explain my problem , I have a file like this: aasdsaffsc23 scdsfsddvf46567 mionome0001.pdb asdsdvcxvds dsfdvcvc2324w What I need to do is to create 1000 files in which myname line listing a sequence of numbers from 0001 to 1000. So I want to have : nomefile0001.txt that must... (10 Replies)
Discussion started by: danyz84
10 Replies

3. UNIX for Dummies Questions & Answers

Best way to parse 1000 scripts for a string?

I have inherited code from a former employee and I need to identify the scripts he disabled with exit 0 at the top. After *many* trials and errors, I finally got this to work alan@p33 => find . -name "*.ksh" -exec sh -c "head -v -n2 '{}' | tail -v -n 1 | grep -H '^exit 0'" \; (standard... (7 Replies)
Discussion started by: alan
7 Replies

4. UNIX for Dummies Questions & Answers

Remove files from tar archive which are more than 1000 days old.

I am not able to extract/remove files older than 1000 days from a tar archive in linux system. #!/usr/bin/perl @file_list = `find /home/x/tmp/ -name *xxMsg* -ctime +7`; $file_name = '/home/x/tmp/new_archive.tar'; for... (1 Reply)
Discussion started by: DannyV
1 Replies

5. Programming

Python: Check 2 text files for string and print contexts

I have 2 text files: cities.txt San Francisco Los Angeles Seattle Dallas master.txt Atlanta is chill and laid-back. I love Los Angeles. Coming to Dallas was the right choice. New York is so busy! San Francisco is fun. Moving to Boston soon! Go to Seattle in the summer. ... (0 Replies)
Discussion started by: pxalpine
0 Replies

6. Shell Programming and Scripting

Adding a line to 1000's of files right after x amt of characters.

I am trying to add a single line of text to every file in a particular folder. There are thousands of files in the folder. Each file contains this same start of the first line: {d "%w- %d %m-, %Y - %T"} <some message here> with the rest of the text following the second curly bracket... (10 Replies)
Discussion started by: dlundwall
10 Replies

7. Shell Programming and Scripting

Script to find the string contain in which file 1000 files.

Hi Greetings i have 1000 files (xmlfiles) and i need to find which file contain the string over 1000 file all file end with txt i tried with grep -c "string" *.txt i am getting an error -bash: /bin/egrep: Argument list too long i have put an script like below #!/bin/bash for line... (9 Replies)
Discussion started by: venikathir
9 Replies

8. Shell Programming and Scripting

move first 1000 files

Hi i have a folder with 27,000 images. I need to process each image using imagemagick. I have got image magick working. I don't want to attempt to process all 27,000 images in one go and thought i would try doing it with 1000 images at a time. Is there some way i can list only the first 1000... (7 Replies)
Discussion started by: timgolding
7 Replies

9. Shell Programming and Scripting

Creating 1000 files using a script

I would like to write a script that would create 1000 files like clm0001.txt to clm1000.txt. All the files would contain the same contents. How do I achieve this using a script?Please help. (2 Replies)
Discussion started by: ggayathri
2 Replies

10. Shell Programming and Scripting

Check all files in directories for string and remove.. possible?

Say I am in /var/adm/bin and I want to search through all the various scripts and such in that directory for a string, say, xxx@yyy.com I want to find every file with that in there and replace it with a single space. Is that possible? Or, is it possible to search every file and get a list... (7 Replies)
Discussion started by: LordJezo
7 Replies
Login or Register to Ask a Question