- Linux - General
(https://www.linuxquestions.org/questions/linux-general-1/)
- - Pattern search in a line
(https://www.linuxquestions.org/questions/linux-general-1/pattern-search-in-a-line-123189/)
jitz
12-06-2003 03:50 AM
Pattern search in a line
Is there a way to get the words in between two given patterns from a single line
druuna
12-06-2003 04:37 AM
This is a solution:
Code:
#!/bin/bash
TESTLINE="Unix and linux are great and wonderfull operating systems."
PATTERN_1="are"
PATTERN_2="operating"
echo "Original:"
echo "${TESTLINE}"
echo ""
echo "Words in between two patterns ('are' and 'operating'):"
echo ${TESTLINE} | sed "s/.*${PATTERN_1}\(.*\)${PATTERN_2}.*/\1/"