के साथ gawk, आप मैच फ़ंक्शन का उपयोग कर सकते हैं:
x="hey there how are you"
echo "$x" |awk --re-interval '{match($0,/(.{4})how(.{4})/,a);print a[1],a[2]}'
ere are
यदि आप perlअधिक लचीले समाधान के साथ ठीक हैं , तो निम्न पैटर्न के पहले तीन वर्णों को प्रिंट करेगा और उसके बाद पैटर्न के बाद 5 वर्ण।
echo hey there how are you |perl -lne 'print "$1$2$3" if /(.{3})(there)(.{5})/'
ey there how
यह सिर्फ वर्णों के बजाय शब्दों पर भी लागू किया जा सकता है। वास्तविक मिलान स्ट्रिंग से पहले एक शब्द प्रिंट होगा।
echo hey there how are you |perl -lne 'print $1 if /(\w+) there/'
hey
पैटर्न के बाद एक शब्द प्रिंट होगा:
echo hey there how are you |perl -lne 'print $2 if /(\w+) there (\w+)/'
how
निम्नलिखित पैटर्न के पहले एक शब्द, उसके बाद वास्तविक शब्द और पैटर्न के बाद एक शब्द प्रिंट होगा:
echo hey there how are you |perl -lne 'print "$1$2$3" if /(\w+)( there )(\w+)/'
hey there how