Finding non-existing words in a list of files in a directory and its sub-directories


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Finding non-existing words in a list of files in current directory and/or its sub-directories

Hi All,

I have a list of words (these are actually a list of database table names separated by comma).

Now, I want to find only the non-existing list of words in the *.java files of current directory and/or its sub-directories.

Sample list of words: table_one,table_ten,table_x,table_y,table_z

Type of files in current directory and/or its sub-directories: *.java

Suppose, 2 words (say table_ten and table_z) are not exist in any of the *.java files in current directory and/or its sub-directories, then print these 2 words as output as shown below.

Non-existing words are: table_ten,table_z

Please help.

Thanks in advance.

Last edited by Bhanu Dhulipudi; 01-12-2016 at 05:38 AM..
# 2  
1. What shell/OS are you using?
2. What have you tried? (It's easier and quicker for forum members to help you from where you're stuck; rather than give you a solution they have to work from scratch, just for you)
3. To help you get started, you could try a combination of find and grep. Let us know what you could come up with.
# 3  
@balajesuri Thanks for your reply :-)

I am using bash shell.

I guess, this can be done with shell scripting using a for loop.

Last edited by Bhanu Dhulipudi; 01-12-2016 at 06:26 AM..
# 4  
A crude and inefficient way:
Code:
for file in $(find /path/to/dir -type f -name "*java")
do
    for word in table_one table_two table_three
    do
        if grep -q $word $file
        then
            continue
        else
           echo "$file does not contain $word"
        fi
    done
done


Last edited by balajesuri; 01-12-2016 at 07:22 AM.. Reason: syntax correction
# 5  
Try (untested, assuming table names in a one line file):
Code:
awk -F, '
NR == 1         {for (n=split($0, T); n>0; n--) TBL[T[n]]=n
                 next
                }
$0 in TBL       {delete TBL[$0]
                }
END             {print "non-existing:"
                 for (t in TBL) print t
                }
' tblfile *.java

# 6  
@RudiC Thanks for your reply :-)

After ran the script code, got the below error message.

bash-3.2$ ./test.sh
Syntax Error The source line is 1.
The error context is
<<< >>>
awk: 0602-500 Quitting The source line is 1.
bash-3.2$
# 7  
What files did you supply to the script?
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

List all files and directories in the current directory separated by commas and sorted by crtime

What I know so far: ls -A will list all files except those starting with a dot ls -d will list all directories ls -m will separate contents by commas For getting crtimes use: stat filename will give me the inode number or ls -i filename will give... (13 Replies)
Discussion started by: chstewar
13 Replies

2. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Finding the Files In the Same Name Directories

Hi, In the Unix Box, I have a situation, where there is folder name called "Projects" and in that i have 20 Folders S1,S2,S3...S20. In each of the Folders S1,S2,S3,...S20 , there is a same name folder named "MP". So Now, I want to get all the files in all the "MP" Folders and write all those... (6 Replies)
Discussion started by: Siva Sankar
6 Replies

4. UNIX for Dummies Questions & Answers

Appending lines from an existing list to each line in another existing list

Evening all ! I would like to ask your expertise on how to accomplish the following ; I have 2 lists, and would like each line from list2 to be appended to each line in list1, resulting in list3 ; List1; alpha beta charlie List2; one two three (4 Replies)
Discussion started by: TAPE
4 Replies

5. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

6. UNIX for Dummies Questions & Answers

Count number of files in directory excluding existing files

Hi, Please let me know how to find out number of files in a directory excluding existing files..The existing file format will be unknown..each time.. Thanks (3 Replies)
Discussion started by: ammu
3 Replies

7. Shell Programming and Scripting

Finding directory and sub-directories individual size in Perl

Hi, Can anyone redirect to an existing thread or provide some info on how to find the size of a directory and it's sub-directories using a single script ? I tried finding a similar thread but in vain. I'm a newbie and any help would be greatly appreciated. Thanks in advance. (3 Replies)
Discussion started by: ryder
3 Replies

8. UNIX for Dummies Questions & Answers

List files that are not directories from current directory

I can't manage to list all files that are not directories from current directory. (2 Replies)
Discussion started by: beni22sof
2 Replies

9. UNIX for Dummies Questions & Answers

finding largest files (not directories)?

hello all. i would like to be able to find the names of all files on a remote machine using ssh. i only want the names of files, not directories so far i'm stuck at "du -a | sort -n" also, is it possible to write them to a file on my machine? i know how to write it to a file on that... (2 Replies)
Discussion started by: user19190989
2 Replies

10. UNIX for Dummies Questions & Answers

Finding executable files in all directories

This is probably very easy but I would like to know a way to list all my files in all my directories that are readable and executable to everyone. I was told to use find or ls and I tried some stuff but couldnt get it to work. I understand that its dangerous to have files with these permissions for... (4 Replies)
Discussion started by: CSGUY
4 Replies

Featured Tech Videos