bash - Solved: Read two files simultaneously and creating one from it -
very new forum, sorry errors in post.
i new bash scripting, understand of basics. scenario follows: have server load of data via curl. parsed (xml format), , these results extract data want. curl statement writes it's output file called temp-rec-schedule.txt below code use values want use in further calculation.
mp=`cat temp-rec-schedule.txt | grep "<ns3:mediapackage" | awk -f' ' '{print $3}' | cut -d '=' -f 2 | awk -f\" '{print $(nf-1)}'` rec_time=`cat temp-rec-schedule.txt | grep "<ns3:mediapackage" | awk -f' ' '{print $2}' | cut -d '=' -f 2 | awk -f\" '{print $(nf-1)}'`
so still work perfectly. output of above code respectively (if written 2 separate files) :
mp output:
b1706f0d-2cf1-4fd6-ab60-ae4d08608f1f fd578fcc-342c-4f6c-986a-794ccb1abd0c ce9f40e9-8e2c-4654-ba1c-7f79d35a69fd c31a2354-6f4b-4bfe-b51e-2bac80889897 df342d88-c660-490e-9da6-9c91a7966536 49083f88-4264-4629-80fb-fae480d0bb25 946121c7-4948-4254-9cb5-2457e1b99685 f7bd0cad-e8f5-4e3d-a219-650d07a4bb34
rec_time output:
2014-09-15t07:30:00z 2014-09-19t08:58:00z 2014-09-22t07:30:00z 2014-10-13t07:30:00z 2014-10-17t08:58:00z 2014-10-20t07:30:00z 2014-10-22t13:28:00z 2014-10-27t07:30:00z
what want create file line1 file1 appended line1 file2. i.e. :
b1706f0d-2cf1-4fd6-ab60-ae4d08608f1f 2014-09-15t07:30:00z fd578fcc-342c-4f6c-986a-794ccb1abd0c 2014-09-19t08:58:00z
and on.
how can bash? not familiar perl, know little bit bash, if possible, in bash.
further, here, want compare 2 files contain same mp variable, has 2 different time values assigned it, subtract 1 value other, , calculate amount of hours has passed between. calculate amount of hours has surpassed between publishing video on our system, , start time of recording.
basically: file1's output:
b1706f0d-2cf1-4fd6-ab60-ae4d08608f1f 2014-09-15t07:30:00z
file2's output:
b1706f0d-2cf1-4fd6-ab60-ae4d08608f1f 2014-09-15t09:30:00z
the output of script should yield value of 2 hours.
anybody this? :-)
would appreciated!
you're better off using awk
whole thing. like:
awk '/<ns3:medipacakge/{gsub("\"",""); split($3,mp,"="); split($2,rt,"="); print mp[2],rt[2]}' temp-rec-schedule.txt
Comments
Post a Comment