I have string content as TXT file = 70 kb. I want to find and cut string with pattern.
Sample content.
"<div jsname="Rfh2Tc" id="i3" role="alert"></div></div></div></div><div role="listitem"><div jsmodel="CP1oW" data-params="%.@.[1696921474,"พื้นที่",null,2,[[TARGET_STRING,[["BKK"
I use this code in bash script.
DATA=`cat content.txt`
DATA=${DATA##*พื้นที่"}
DATA=${DATA%\,\[\[*}
echo $DATA
It's work. But! When it run, It very slow for 60 KB text file. and high CPU usage. How can I fix it, Please help me.
CodePudding user response:
You could use sed
:
DATA=$( sed 's/.*FrontPattern:\[\(.*\?\)\]:BackPattern.*/\1/' <<< "$DATA" )
For a 70 KiB text file, this takes less than 20 ms on my machine.