0

I want to read text between two particular words from a text file in unix shell scripting. For example in the following:

"My name is Sasuke Uchiha."

I want to get Sasuke.

1
  • 3
    you will get better answers if you post what you have tried instead of expecting someone to write the code for you; just a tip... Commented Apr 25, 2013 at 14:45

2 Answers 2

1

This is one of the many ways it can be done:

To capture text between "is" and "Uchiha":

sed -n "s/^.*is \(.*\)Uchiha.*/\1/p" inFile
Sign up to request clarification or add additional context in comments.

Comments

0

I'm tempted to add a "let me google that for you" link, but it seems like you're having a hard enough time as is.

What's the best way to find a string/regex match in files recursively? (UNIX)

Take a look at that. It's similar to what you're looking for. Regex is the go to tool for matching strings and such. And Grep is the easiest way to use it from shell in unix.

Take a look at this as well: http://www.robelle.com/smugbook/regexpr.html

1 Comment

Actually, if you're just looking through a single file, use grep PATTERN FILENAME. In your case, you're going to type "grep Sasuke textfile.txt" in the command line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.