Find a word in input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find a word in input file
# 1  
Old 09-27-2010
Find a word in input file

Hi,

I had a input file containing,
Code:
abcdefghij;20100903040607;1234567891;GLOBAL;
abc123;20100903040607;12345;09;thestdf;
def456;20100903040607;67891;04;bnkim;

I need to search word GLOBAL in my file.
If it is found then
do something
else
do other thing

How can i write if loop for this criteria in .ksh file?

Last edited by Franklin52; 09-27-2010 at 06:56 AM.. Reason: Please use code tags!
# 2  
Old 09-27-2010
Use our search function right above:

Google Search Results for if grep | The UNIX and Linux Forums

Regards
# 3  
Old 09-27-2010
I updated code with,
Code:
grep -i "GLOBAL" FILE
if [ $? -eq 0 ]
then
  echo "grep successful"
 else
  echo "unsucessful"
fi

but receiving error as ,
Code:
grep: 0652-033 Cannot open FILE.

Please help me out to resolve this error.

Last edited by Scott; 09-27-2010 at 08:24 AM.. Reason: Code tags, please...
# 4  
Old 09-27-2010
What does this command tell you?
Code:
ls -l FILE

# 5  
Old 09-27-2010
Code:
-rwxr--r--   1 alf      archive          45 Sep 27 11:21 MigBIOS.CR.GLOBAL.0100924021422.CSV


Last edited by Scott; 09-27-2010 at 08:25 AM..
# 6  
Old 09-27-2010
So your command is:
Code:
grep -i "GLOBAL" MigBIOS.CR.GLOBAL.0100924021422.CSV

and the error message is:
Code:
grep: 0652-033 Cannot open MigBIOS.CR.GLOBAL.0100924021422.CSV

Is that correct?
# 7  
Old 09-27-2010
YES. Thats the one.
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