Here file.txt contains fields of records.
My intension is to grep for the 3 letter 'swi' in one of filed, this field will contain swi as part of word.
And next grep is to grep for a 'DEV' field, this is a single field.
Something like this is much easier to understand when there is a smaple text file. Can you post a small piece for the file, as well as an example of what you hope to obtain as output?
So my understading so far is, if a searching pattern is a part of word, then we should keep it in single quotes. and if the searching pattern is itself a single word, we should keep it in double quotes.
> cat files.txt
123892TX ETV156SWI DEV 14 5:20 5:45 UBXS
123892TX ETV156SWI DEVB 14 6:20 5:45 UBXS
123892TX ETV156SWX DEV 14 7:20 5:45 UBXS
123892TX ETV156swi DEV 14 8:20 5:45 UBXS
123892TX ETV156SWI DEV 14 9:20 5:45 UBXS
This will find "swi" or "SWI" because I tell it to ignore case
> grep -i 'swi' files.txt | grep " DEV " | cut -f6
123892TX ETV156SWI DEV 14 5:20 5:45 UBXS
123892TX ETV156swi DEV 14 8:20 5:45 UBXS
123892TX ETV156SWI DEV 14 9:20 5:45 UBXS
This will only find "swi"
> grep 'swi' files.txt | grep " DEV " | cut -f6
123892TX ETV156swi DEV 14 8:20 5:45 UBXS
Note in both examples, the 2nd line is not included since it has a "DEVB" and I am searching for " DEV " -- a space character before D and after V. Since in double-quotes, I am looking to exactly match. The double quotes are also important when you want to maintain more than one space, as sometimes commands will atuomatically drop out extra space characters.