String search and generating file

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support String search and generating file
# 8  
Old 10-09-2009
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,
SandeepSmilie
# 9  
Old 10-09-2009
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.
# 10  
Old 10-09-2009
Quote:
Originally Posted by pssandeep
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 Smilie
Code:
awk '!/Not/ && /Ok to Proceed/ && NR==15{print "" > "Go.txt"}' file

# 11  
Old 10-23-2009
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
# 12  
Old 10-23-2009
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
# 13  
Old 10-24-2009
Quote:
#!/bin/bash -v
grep "OK to proceed" check.txt
if [ $? -eq 0 ]
then
touch "Ok.txt"
fi
this can be written as,
Code:
grep "OK to proceed" check.txt 1>/dev/null && touch "Ok.txt"

# 14  
Old 10-29-2009
Quote:
Originally Posted by ahmad.diab
use following code:-

Code:
sed -n '/Ok to Proceed/ p' input_file | nawk '($0 !~ "Not") { "touch GO.txt" | getline }'

BR
You can change the path to be


sed -n '/Ok to Proceed/ p' input_file | nawk '($0 !~ "Not") { "touch /the/path/of/file/GO.txt" | getline }'

BR

---------- Post updated at 08:02 AM ---------- Previous update was at 07:59 AM ----------

Quote:
Originally Posted by ahmad.diab
You can change the path to be



Code:

sed -n '/Ok to Proceed/ p' input_file | nawk '($0 !~ "Not") { "touch /the/path/of/file/GO.txt" | getline }'

BR

to change the path use the above bold phrase
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies

2. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

3. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

4. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

5. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

6. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

7. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

8. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

9. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

10. Shell Programming and Scripting

appending string to text file based on search string

Hi, I need to append string "Hi" to the beginning of the lines containing some specific string. How can I achieve that? Please help. Malay (1 Reply)
Discussion started by: malaymaru
1 Replies
Login or Register to Ask a Question