awk

Fill the missing dates using awk

假如想象 提交于 2020-08-24 04:16:15
问题 I have some missing dates in a file. e.g. $cat ifile.txt 20060805 20060807 20060808 20060809 20060810 20060813 20060815 20060829 20060901 20060903 20060904 20060905 20070712 20070713 20070716 20070717 The dates are in the format YYYYMMDD. My intention is fill the missing dates in between the dates if they are missing maximum for 5 day e.g. 20060805 20060806 ---- This was missed 20060807 20060808 20060809 20060810 20060811 ----- This was missed 20060812 ----- This was missed 20060813 20060814

Fill the missing dates using awk

假装没事ソ 提交于 2020-08-24 04:14:48
问题 I have some missing dates in a file. e.g. $cat ifile.txt 20060805 20060807 20060808 20060809 20060810 20060813 20060815 20060829 20060901 20060903 20060904 20060905 20070712 20070713 20070716 20070717 The dates are in the format YYYYMMDD. My intention is fill the missing dates in between the dates if they are missing maximum for 5 day e.g. 20060805 20060806 ---- This was missed 20060807 20060808 20060809 20060810 20060811 ----- This was missed 20060812 ----- This was missed 20060813 20060814

Fill the missing dates using awk

被刻印的时光 ゝ 提交于 2020-08-24 04:14:29
问题 I have some missing dates in a file. e.g. $cat ifile.txt 20060805 20060807 20060808 20060809 20060810 20060813 20060815 20060829 20060901 20060903 20060904 20060905 20070712 20070713 20070716 20070717 The dates are in the format YYYYMMDD. My intention is fill the missing dates in between the dates if they are missing maximum for 5 day e.g. 20060805 20060806 ---- This was missed 20060807 20060808 20060809 20060810 20060811 ----- This was missed 20060812 ----- This was missed 20060813 20060814

sum value of a 3rd row and divide rows in such a way that their sum values matches

风格不统一 提交于 2020-08-10 19:29:45
问题 I have a file as below with n number of rows, I want to total it's sum(based on 3rd column) and distribute rows accordingly in 3 different files(based on sum of each) For example- if we sum all the 3rd column values it's total is coming as 516 and if we divide it by 3 it is 172. So i want to add a rows to a file so it doesn't exceed 172 mark, same with the 2nd file and rest all rows should move to the third file. Just have to make sure sum value of all the 3 files should match(small

How do I detect embbeded field names and reorder fields using awk?

只谈情不闲聊 提交于 2020-08-10 19:20:45
问题 I have the following data: "b":1.14105,"a":1.14106,"x":48,"t":1594771200000 "a":1.141,"b":1.14099,"x":48,"t":1594771206000 ... I am trying to display data in a given order and only for three fields. As the fields order is not guaranteed, I need to read the "tag" for each comma separated column for each line. I have tried to solve this task using awk : awk -F',' ' { for(i=1; i<=$NF; i++) { if(index($i,"\"a\":")!=0) a=$i; if(index($i,"\"b\":")!=0) b=$i; if(index($i,"\"t\":")!=0) t=$i; } printf(

How do I detect embbeded field names and reorder fields using awk?

二次信任 提交于 2020-08-10 19:20:27
问题 I have the following data: "b":1.14105,"a":1.14106,"x":48,"t":1594771200000 "a":1.141,"b":1.14099,"x":48,"t":1594771206000 ... I am trying to display data in a given order and only for three fields. As the fields order is not guaranteed, I need to read the "tag" for each comma separated column for each line. I have tried to solve this task using awk : awk -F',' ' { for(i=1; i<=$NF; i++) { if(index($i,"\"a\":")!=0) a=$i; if(index($i,"\"b\":")!=0) b=$i; if(index($i,"\"t\":")!=0) t=$i; } printf(

How do I detect embbeded field names and reorder fields using awk?

落花浮王杯 提交于 2020-08-10 19:18:59
问题 I have the following data: "b":1.14105,"a":1.14106,"x":48,"t":1594771200000 "a":1.141,"b":1.14099,"x":48,"t":1594771206000 ... I am trying to display data in a given order and only for three fields. As the fields order is not guaranteed, I need to read the "tag" for each comma separated column for each line. I have tried to solve this task using awk : awk -F',' ' { for(i=1; i<=$NF; i++) { if(index($i,"\"a\":")!=0) a=$i; if(index($i,"\"b\":")!=0) b=$i; if(index($i,"\"t\":")!=0) t=$i; } printf(

Escaping backslash in AWK

久未见 提交于 2020-08-10 18:48:44
问题 I'm trying to understand why the command below doesn't work (output is empty): echo 'aaa\tbbb' | awk -F '\\t' '{print $2}' I would expect the output to be 'bbb'. Interestingly this works (output is 'bbb'): echo 'aaa\tbbb' | awk -F 't' '{print $2}' And this works as well (ouptut is 'tbbb'): echo 'aaa\tbbb' | awk -F '\\' '{print $2}' It looks as if \\\t is read as backslash followed by tab instead of escaped backslash followed by t . Is there a proper way to write this command? 回答1: You need to

Escaping backslash in AWK

若如初见. 提交于 2020-08-10 18:47:31
问题 I'm trying to understand why the command below doesn't work (output is empty): echo 'aaa\tbbb' | awk -F '\\t' '{print $2}' I would expect the output to be 'bbb'. Interestingly this works (output is 'bbb'): echo 'aaa\tbbb' | awk -F 't' '{print $2}' And this works as well (ouptut is 'tbbb'): echo 'aaa\tbbb' | awk -F '\\' '{print $2}' It looks as if \\\t is read as backslash followed by tab instead of escaped backslash followed by t . Is there a proper way to write this command? 回答1: You need to

Escaping backslash in AWK

醉酒当歌 提交于 2020-08-10 18:47:08
问题 I'm trying to understand why the command below doesn't work (output is empty): echo 'aaa\tbbb' | awk -F '\\t' '{print $2}' I would expect the output to be 'bbb'. Interestingly this works (output is 'bbb'): echo 'aaa\tbbb' | awk -F 't' '{print $2}' And this works as well (ouptut is 'tbbb'): echo 'aaa\tbbb' | awk -F '\\' '{print $2}' It looks as if \\\t is read as backslash followed by tab instead of escaped backslash followed by t . Is there a proper way to write this command? 回答1: You need to