Linux / UNIX Tech Support Forum
This is a discussion on Unix Shell: Check if Word exist in file or not within the Shell scripting forums, part of the Development/Scripting category; Hello, I want to check if some word exist or not on some file By Example : word is : ...
Register free or login to your account to remove all advertisements.
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
Thread Tools | Display Modes |
|
|||
|
Hello,
I want to check if some word exist or not on some file By Example : word is : nixcraft file called : /root/shell.txt and i want to check if nixcraft word exist on /root/shell.txt file with if statement or another tool Any Ideas |
|
||||
|
try something as follows:
Code:
#!/bin/bash FILE=/root/shell.txt grep -w "nixcraft" $FILE >/dev/null if [ $? -eq 0 ] then echo "Word found!" else echo "Word NOT found!" fi
__________________
Vivek Gite |
![]() |
|
|
| Tags |
| if command, linux, shell scripting, unix |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find a word in a file, and change a word beneath it ?? | vikas027 | Shell scripting | 3 | 10th June 2010 09:38 AM |
| Unix command to check memory usage | sweta | HP-UX | 3 | 24th February 2010 10:54 PM |
| shell script to search specific file from txt file inside zip file and extract it | aasif.shaikh | Shell scripting | 2 | 31st May 2008 06:44 PM |
| word search in file | chandanperl | Coding in General | 2 | 11th March 2008 10:16 AM |
| HP unix check filesystem for errors | jerry | HP-UX | 0 | 9th June 2007 01:49 AM |