LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to find a string in the file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-a-string-in-the-file-932942/)

AKB48 03-05-2012 11:11 PM

how to find a string in the file
 
for instance
a string:"112321324AAAhow are you?AAAsdfsfdsfds" in file "test.txt"

i want to find the string between "AAA" and "AAA".

it means that i should find "how are you?" in test.txt

what should i do?
anyone help? thanks

spazticclown 03-05-2012 11:49 PM

If you know the quote you are looking for: "how are you?"
You can try:
Code:

$ cat test.txt | grep "how are you?"
This will output the lines where the string exists.

Hope this helps you out.

grail 03-06-2012 12:37 AM

I think you need to provide more information, ie do we know ahead of time what the string is between AAA's?

AKB48 03-06-2012 01:27 AM

Quote:

Originally Posted by grail (Post 4619575)
I think you need to provide more information, ie do we know ahead of time what the string is between AAA's?

no, i just need to find the string between "AAA" and "AAA",we don't know the string "how are you?" at first

i think it regular expression may solve it

grail 03-06-2012 02:54 AM

So something like:
Code:

sed -rn 's/.*AAA(.*)AAA.*/\1/p' test.txt


All times are GMT -5. The time now is 09:52 AM.