Check in command line if a word is missing when a word exist in multiple files

how to grep multiple words in a single line in unix
findstr examples
grep command
multiple grep commands
grep word in file
grep multiple words in bash
findstr multiple strings

How can I have a list that tells me when a word (SecondWord in my example) is missing when another word (FirstWord in ma example) has been write.


Hello FirstWord ... SecondWord


... FirstWord ...

FirstWord ... SecondWord

FirstWord ... ...

Hello ... SecondWord


Hello FirstWord ... SecondWord

FirstWord ...

I would like a file at the end with line and filename :

3 : File1

5 : File1

2 : File2

I think what I try to do is overkill :/

grep -r -n 'FirstWord ' Sources/ --include=\*.txt | awk -F: '{print $2":"$1}' > $filename
while read line; 
        for key in "${!ary[@]}";
                if [[ $filesAwaitable["$key"] != *"${ary[$key]}"* ]]; then
                    filesAwaitable["$key"] = "${ary[$key]}"
                    echo "${ary[$key]}";
                #grep -n -r 'SecondWord' line | awk -F: '{print $2":"$1}'
    done < $filename

Thx for your help

In case a Perl solution is okay, here is a straightforward one with the same regular expression as for GNU grep:

perl -ne 'print "$. : $ARGV\n" if /FirstWord((?!SecondWord).)*$/; close ARGV if eof' File?.txt

How can I use this command in all Source/ folder for all .txt files?

You can use find for this:

find Source -name \*.txt|xargs perl …

(without the File?.txt at the end of the perlcommand).

How to Grep for Multiple Strings, Patterns or Words, Use grep to search for multiple patterns or words in a file by following examples in this guide. The grep tool is one of the most famous command-line tools. We stored the file in the directory of the test user, that is, in /home/test/sample.txt To avoid missing something when you search for multiple patterns,� This only checks if its found on the first line, what if the word your searching for is found at the end of the file? How would you fix the above code? – unixcreeper Jan 26 '17 at 16:00 @unixcreeper As I can see it checks all lines, if it finds in a line it says fund if not "not found" and runs search again until EOF (end of the file).

In my example I want to know when SecondWord is missing when FirstWord has been written before.

If you have a grep which understands perl regular expressions, you can directly specify a pattern for FirstWord not followed by SecondWord anywhere until the end of line:

grep -nP 'FirstWord((?!SecondWord).)*$' File?.txt

This yields for the given examples:

File1.txt:3:... FirstWord ...
File1.txt:5:FirstWord ... ...
File2.txt:2:FirstWord ...

To rearrange that to the desired output format, you can pipe it through

awk -F: '{print $2,":",$1}'

Findstr - Search for strings - Windows CMD, The default behaviour of FINDSTR is to match any word, so FINDSTR "blue the last line of a Windows text file if it is missing the EOL marker of <CR><LF>. If several filenames are to be searched they must all exist or FINDSTR will fail with � Example To start Word and open the template file Myfax.dotx, stored on the C drive, type the following at the command prompt: /t c:\Myfax.dotx. Example To start Word and open multiple files, such as MyFile.docx and MyFile2.docx, each stored on the C drive, type the following at the command prompt: /t c:\MyFile.docx c:\MyFile2.docx

If the shell is bash, the problem can be solved easily with the extended pattern matching operator !(pattern), which matches anything except the given pattern:

shopt -s extglob    # enable extended pattern matching features
for file in "$@"
do  lineno=0
    while read line
    do  ((++lineno))
        case "$line" in *FirstWord!(*SecondWord))   echo $lineno : $file
    done <$file

Check whether all lines of file occur in different file, comm -13 <(sort -u file_1) <(sort -u file_2). This command will output lines unique to file_2 . So, if output is empty, then all file_2 lines are� I have folders containing multiple Word files each and when I search one for a specific word or phrase I get several false positive results with a list of documents that do not contain what I was searching for. This did not seem to be a problem with previous version of Word but started when I "upgraded" to Word 2013.

grep, egrep, fgrep -- match patterns in a file, If you include special characters in patterns typed on the command line, escape If you specify multiple input files, the name of the current file precedes each output line. utilities; however, when the multiple-byte marker is missing you can use the -U option or only match lines where the pattern matches a whole word. grep searches for text in files recursively in a directory. The -l flag for grep tells it to only output file names when it finds a word match. The -r flag tells grep to search recursively in the directory, i.e. it will also look in subfolders if applicable. --exclude-dir=".git" is optional; it tells grep to ignore files in the.git directory.

[PDF] grep, awk and sed – three VERY useful command-line utilities Matt , In this example, grep would loop through every line of the file "a_file" and print out every line that contains the word 'boo': boot book booze boots. Useful Options . Processing Multiple Items with the For Command. You'll often want to write batch files that process "all" of a certain type of file. Command-line programs can deal with filename wildcards: For example, you can type delete *.dat to delete all files whose name ends with .dat. In batch files, you can accomplish this sort of thing with the for loop.

Text Processing Commands, #!/bin/bash # Crude word frequency analysis on a text file. # This is a more efficient -f "$1" ] # Check if file exists. then echo "File \"$1\" does not exist. The default is 10 lines, but a different number can be specified. The command has� Using find to Find a Specific Word in a File While the find command’s syntax is more complicated than grep, some prefer it. find. -name "*.php" -exec grep "pattern" {} \; This command will use find’s -exec flag to pass the found files to grep for searching.