The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Emergency UNIX and Linux Support !! Help Me!!
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 3 Weeks Ago
ahmad.diab's Avatar
ahmad.diab ahmad.diab is offline
Registered User
  
 

Join Date: May 2008
Location: Amman Jordan in MEA
Posts: 228
Code:
awk '!/Not/ && /Ok to Proceed/ && NR==15{print "" > "Go.txt"}' file
the above code means:-
if the row does not contain "NOT" && contain "Ok to Proceed" && the row number ==15 then do
print "nothing" and send it to "GO.txt" file


---------- Post updated at 07:36 AM ---------- Previous update was at 07:34 AM ----------

Quote:
Originally Posted by ahmad.diab View Post
Code:
awk '!/Not/ && /Ok to Proceed/ && NR==15{print "" > "Go.txt"}' file
the above code means:-
if the row does not contain "NOT" && contain "Ok to Proceed" && the row number ==15 then do
print "nothing" and send it to "GO.txt" file
last sentence means create GO.txt

---------- Post updated at 07:36 AM ---------- Previous update was at 07:36 AM ----------

Quote:
Originally Posted by ahmad.diab View Post
Code:
awk '!/Not/ && /Ok to Proceed/ && NR==15{print "" > "Go.txt"}' file
the above code means:-
if the row does not contain "NOT" && contain "Ok to Proceed" && the row number ==15 then do
print "nothing" and send it to "GO.txt" file


---------- Post updated at 07:36 AM ---------- Previous update was at 07:34 AM ----------



last sentence means create GO.txt
and the file path is the current path.
  #2 (permalink)  
Old 10-05-2009
Casey's Avatar
Casey Casey is offline
Registered User
  
 

Join Date: Jun 2009
Location: Buenos Aires
Posts: 18
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.
  #3 (permalink)  
Old 10-09-2009
pssandeep pssandeep is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 35
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
  #4 (permalink)  
Old 10-09-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 453
You can do various things, such as:

1. Strip the comment, and pipe only appropriate input to grep as

Code:
sed 's/^#//' | grep '<PATTERN>'
2. Extract part of file, using tail or head as:
tail -n +11 FILE | grep '<PATTERN>'

3. or search for 2nd occurrence and so on.

Select an appropriate way, by analyzing your data.
  #5 (permalink)  
Old 10-09-2009
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,428
Quote:
Originally Posted by pssandeep View Post
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
Not clear
Code:
awk '!/Not/ && /Ok to Proceed/ && NR==15{print "" > "Go.txt"}' file
  #6 (permalink)  
Old 10-23-2009
mrlinux mrlinux is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 1
Here it goes.

Code:
#!/bin/bash  -v
grep "OK to proceed" check.txt
if [ $? -eq 0 ]
then
 touch "Ok.txt"
fi

Last edited by zaxxon; 10-23-2009 at 09:51 AM.. Reason: code tags
  #7 (permalink)  
Old 10-23-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0