I have .txt files with the following structure:20170515000650883,208,-32,-896,stand20170515000651883,336,96,-928,stand20170515000652982,368,64,-896,stand20170515000653982,256,-48,-816,lie20170515000654982,368,48,-832,lie20170515000655982,15081,32,-688,lie20170515000656982,15081,48,-864,lie20170515000657983,15081,112,-1072,lie20170515000658983,15081,-32,-992,lie20170515000659983,15081,-48,-1072,lie20170515000700983,15081,-32,-880,lie20170515000701983,15081,16,-832,stand20170515000702983,15081,-48,-720,stand20170515000703983,15081,0,-896,stand20170515000704983,15081,112,-880,lie20170515000705983,15081,-48,-1072,lie...My goal is to search for lie events represented in the last column. This I realized withsed -n '13,$s/lie/&/p' $subj > $SUBJECTS_DIR/temp.txtwhere I started the search from line13 and saves all lines with 'lie' to my temp-file. But is it possible to collect data during the sed-command?The first column contains a timestamp: so when lie=TRUE I want to collect the value from column_1; also, when the last lie of this sequence (in total 8 'lie' occurs the corresponding value of column_1 is needed to calculate the time-difference. The search should be continued until file ends.Has someone any idea how to collect these informations during sed?
using sed in loop
shell script;sed
You can use awk for this.awk -F, '/lie/{a[++i>2?2:i]=$1}END{print a[2] - a[1] }' input .txtThe awk command will store the first and the most recent timestamp that matches lie in an array. Once the file has been read, awk will subtract the first match from the last match.