![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Emergency UNIX and Linux Support !! Help Me!! Post your urgent questions here for highest visibility. Posting a new thread to this forum requires Bits. We monitor this forum to help people with emergencies, but we do not guarantee response time or answers. This forum is "best effort" only. Members who reply to posts here receive a bonus of 1000 Bits per reply. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Search for string in a file and extract another string to a variable | daikeyang | Shell Programming and Scripting | 6 | 03-20-2009 08:45 PM |
| How to search a string in a file. | prathap | UNIX for Dummies Questions & Answers | 1 | 07-17-2007 03:41 AM |
| String search in log file | sliver | Shell Programming and Scripting | 1 | 07-12-2006 08:09 AM |
| appending string to text file based on search string | malaymaru | Shell Programming and Scripting | 1 | 06-09-2006 09:53 AM |
| please help me to search string in a file ...... | swamymns | Shell Programming and Scripting | 2 | 02-01-2006 12:20 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|
|
|||||
|
What about using fgrep or -F flag?
Maybe something like this... If the fixed string "Not ok to proceed" is not found in the file, then just check if "ok to Proceed" exists; if it does, then generate the output. Code:
if [[ `grep -Fi "Not ok to Proceed" ./a.txt` -ne 0 ]]
then
if [[ `grep -ic "ok to Proceed"` ]]
then
touch go.txt
fi
fi
Try with fgrep instead of grep -F if it doesn't work properly. |
|
||||
|
Thanks for all of ur responses
Its working with grep. I have one more question on this, suppose if i want to go and check the text file based on line no For example, I need to go to the line 15 in text file and then check for the String "OK to Proceed" or "Not ok to Proceed" because my text file will contain a comment on 10th line with "Not Ok to Proceed" So either i need to go based on line number or need to check for the second occurence of the "Not Ok to Proceed" Please advice Thanks in Advance, Sandeep ![]() |
|
||||
|
You can do various things, such as:
1. Strip the comment, and pipe only appropriate input to grep as Code:
sed 's/^#//' | grep '<PATTERN>' tail -n +11 FILE | grep '<PATTERN>' 3. or search for 2nd occurrence and so on. Select an appropriate way, by analyzing your data. |
|
||||
|
Quote:
![]() Code:
awk '!/Not/ && /Ok to Proceed/ && NR==15{print "" > "Go.txt"}' file
|
|
|||||
|
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.) Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red. Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property. Thank You. The UNIX and Linux Forums |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|