Find a word in input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find a word in input file
# 8  
Old 09-27-2010
If ls -l FILE gives:
Code:
-rwxr--r--   1 alf      archive          45 Sep 27 11:21 MigBIOS.CR.GLOBAL.0100924021422.CSV

That would make "FILE" a directory?
# 9  
Old 09-27-2010
I am writting this code into my shell script function which takes file name as command line agrument which then i stored in FILE variable.

FILE=$1
where $1 is MigBIOS.CR.GLOBAL.0100924021422.CSV.
# 10  
Old 09-27-2010
Hi.

So, the grep should be grep -i "GLOBAL" $FILE
# 11  
Old 09-27-2010
If loop condition

Now its working fine.
Thanks a lot.
Its my silly mistake Smilie


Could you please let me know, how can I put the if loop condition for this?

Code:
if [ `grep -i "GLOBAL" $FILE` -eq 0 ]
 then
   echo "grep successful : GLOBAL"
  elif [ `grep -i "PARTIAL" $FILE` -eq 0 ]
then
echo "grep successful : PARTIAL"
fi

Thanks in advance.

Moderator's Comments:
Mod Comment Please use code tags.

Last edited by Scott; 09-27-2010 at 08:54 AM..
# 12  
Old 09-27-2010
Code:
if grep -qi GLOBAL "$FILE"; then
   echo "grep successful : GLOBAL"
elif grep -qi PARTIAL "$FILE"; then
  echo "grep successful : PARTIAL"
fi

# 13  
Old 09-27-2010
Thank you so much for your pro-active help. Smilie
# 14  
Old 10-04-2010
Computer

Quote:
Originally Posted by scottn
If ls -l FILE gives:
Code:
-rwxr--r--   1 alf      archive          45 Sep 27 11:21 MigBIOS.CR.GLOBAL.0100924021422.CSV

That would make "FILE" a directory?
It's the filename itself.
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

2. Shell Programming and Scripting

How to find biggest word in a file....?

With any cmd like sed grep ask etc... (1 Reply)
Discussion started by: sidpatil
1 Replies

3. UNIX for Dummies Questions & Answers

Find word in a large file

Hi all I am working on disallowing users to use easy passwords in pam.d setting on RHEL 5.7 and SuSe 11, and I was hoping to add more words into the current cracklib dict, so I use "echo" command to append new words into the file I dont want to add the same words into the dict, I think I... (2 Replies)
Discussion started by: hedkandi
2 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. Shell Programming and Scripting

How to find a particular word from a file

Hello Experts, I have to count the word like "RESULT_CODE: : -6" from the multiple files names like req.result_2_vqx-71144750.log for a particular date. Lets suppose the date is 10 OCT 2011. How I can do it with a single command in Solaris environment. Reagrds Oracle User (8 Replies)
Discussion started by: Oracle_User
8 Replies

6. Shell Programming and Scripting

Find word in file then get following characters

Hello, I have several xml files from which I want to find and return a particular string I want to locate the InId="00000008". Now that is inlcuded within a tag and ofcourse the number is different every time this is what I came up with given that after greping the line that contains the... (6 Replies)
Discussion started by: TasosARISFC
6 Replies

7. Shell Programming and Scripting

Exclude specific word from input file problem asking...

Hi, Below is my input file and desired output file: Input file: >header_N_1 ASFDGDGNDGEGWETWRYWTETWNETOWETWETWNETTETNWET . . Desired output file: >header_N_1 ASFDGDGDGEGWETWRYWTETWETOWETWETWETTETWET . . From the input file, I just hope to exclude the 'N' word from its content... (5 Replies)
Discussion started by: patrick87
5 Replies

8. Shell Programming and Scripting

How to find a count of a word within a file

Hello, I'm looking for a wait to count the number of occurrences of a certain string of characters within a file. The file that I trying to parce has segments within the file that have a header and footer to each segment and I'm trying to do a count of the header string and compare it to a count... (9 Replies)
Discussion started by: bd_joy
9 Replies

9. Shell Programming and Scripting

find a word in a file, and change a word beneath it ??

Hi all, I have a file with lines written somewhat like this. aaaa ccc aa linux browse = no xssxw cdcedc dcsdcd csdw police dwed dwd browse = no cdecec (2 Replies)
Discussion started by: vikas027
2 Replies

10. UNIX for Dummies Questions & Answers

how to find a word repeated in a file

Hi everyone, I have a file in which a word is repeated more than one time and I want to know how many times it is repeated. ex: if i repeated word 'guru' in 10 lines I can get the o/p as: cat filename | grep -c 'guru'. How ever if the word is repeated more than one time, then how can I... (4 Replies)
Discussion started by: gurukottur
4 Replies
Login or Register to Ask a Question