简体   繁体   中英

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.

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

将打印出:

xxx
 $ sed -n '/WORD1/,/WORD2/p' /path/to/file 
 $ sed -n '/FOO/,/BAR/p' test.txt
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM