LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-05-2012, 11:11 PM   #1
AKB48
LQ Newbie
 
Registered: Feb 2012
Posts: 9

Rep: Reputation: Disabled
Smile 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
 
Old 03-05-2012, 11:49 PM   #2
spazticclown
Member
 
Registered: Sep 2010
Distribution: Fedora, Android, CentOS
Posts: 91
Blog Entries: 2

Rep: Reputation: 21
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.
 
Old 03-06-2012, 12:37 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,564

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
I think you need to provide more information, ie do we know ahead of time what the string is between AAA's?
 
Old 03-06-2012, 01:27 AM   #4
AKB48
LQ Newbie
 
Registered: Feb 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
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
 
Old 03-06-2012, 02:54 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,564

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
So something like:
Code:
sed -rn 's/.*AAA(.*)AAA.*/\1/p' test.txt
 
1 members found this post helpful.
  


Reply

Tags
string


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
find string in txt file Glenn_UOI Programming 6 10-07-2011 09:50 AM
Perl find file and then replace string in file moos3 Programming 5 07-29-2009 07:10 AM
How to find a particular string occurance position in a file? vigneshinbox Programming 5 04-02-2009 11:52 PM
How to find a match string in conf file Ameii83 Linux - Newbie 6 08-12-2008 07:42 PM
how to find out particular string in a file mksc Linux - Newbie 1 06-23-2008 03:04 AM


All times are GMT -5. The time now is 12:28 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration