I was able to extract numbers (ids) between pattern(Available for user: and Chosen by user:)and match if a particular user chose an id from what was available to him from list of ids
Available for user:75=1654 at Time=5504.09
Chosen by user:75=1655
Available for user:10=1300 at Time=550.09
Available for user:10=1301 at Time=550.09
Available for user:10=1303 at Time=550.09
Chosen by user:10=1301
I used sed pattern given in reply to my question at compare available list with chosen ids in shell script
The sed pattern used was this
/^Avail/{
s/[^=]*=([^ ]*).*/\1/;H
}
/^Chosen/{
s/.*=//;G;h;x;y/\n/,/
s/,/ is ab in /;s/$/,/
/(.*) is.*,\1,/s/ab/pre/
s/(ab|pre) in ,(.*),/\1sent in \2/
p;s/.*//;x
}
Now i have a file with globalID and localID added after line "Chosen by user:" i.e.
Available for user:75=1654 at Time=5504.09
Chosen by user:75=1655
globalID=1000 localID=1655
Available for user:10=1300 at Time=550.09
Available for user:10=1301 at Time=550.09
Available for user:10=1303 at Time=550.09
Chosen by user:10=1301
globalID=1020 localID=1301
Available for user:20=1400 at Time=550.09
Available for user:20=1501 at Time=550.09
Available for user:20=1503 at Time=550.09
Chosen by user:20=1503
globalID=1030 localID=1503
Now i want print globalID in each line for each match and no match in two seperate files, file1 and file2 .The output for file1 (match case) where globalID of an id selected from available list by particular user is stored as:
1020
1030
The output for file2 (no match case) where globalID of an id not selected from available list by particular user is stored as:
1000
I tried
sed -nrf script.sed input.txt | grep absent -A1 > file2
and
sed -nrf script.sed input.txt | grep present -A1 > file1
but it does not give next line of source file instead it gives next line of sed script output.
-Poption to use PCREs which aren't supported in any standard UNIX tool. Grep is best for doingg/re/p, sed is best for doings/old/new/, for any text processing that's more than that you should really consider just using awk - it's a tiny, simple language used by a very powerful text processing tool that is standard on all UNIX boxes.