choujayyl
choujayyl

Reputation: 111

how can i get the content of between two special strings in shell

I have two special characters,i want get the content of between them in shell.

Don't use awk ,because my linux can't find awk.

Upvotes: 0

Views: 17435

Answers (3)

MattyV
MattyV

Reputation: 41

echo "This is a #TEST%" | grep -o \#[a-zA-Z.0-9]*\%

will yield

#TEST%

You can also strip the special characters using sed..

echo "This is a #TEST%" | grep -o \#[a-zA-Z.0-9]*\% | sed 's/#//g' | sed 's/%//g'

to yield

TEST

Upvotes: 3

choujayyl
choujayyl

Reputation: 111

 $ sed -n '/WORD1/,/WORD2/p' /path/to/file 
 $ sed -n '/FOO/,/BAR/p' test.txt

Upvotes: 2

Tim
Tim

Reputation: 5379

echo "ABxxxDE" | sed -e 's/AB\(.*\)DE/\1/g'

Will print out:

xxx

Upvotes: 3

Related Questions