awk-formatting

Using variables in printf format

淺唱寂寞╮ 提交于 2019-12-22 03:56:50
问题 Suppose I have a file like this: $ cat a hello this is a sentence and this is another one And I want to print the first two columns with some padding in between them. As this padding may change, I can for example use 7 : $ awk '{printf "%7-s%s\n", $1, $2}' a hello this and this Or 17 : $ awk '{printf "%17-s%s\n", $1, $2}' a hello this and this Or 25 , or... you see the point: the number may vary. Then a question popped: is it possible to assign a variable to this N , instead of hardcoding the

change the date of month in number format in awk [duplicate]

橙三吉。 提交于 2019-12-13 09:29:56
问题 This question already has answers here : Calculate date difference between $2,$3 from file in awk (2 answers) Closed 6 years ago . File 1 P1,06/Jul/2013,09/Jul/2013 P2,06/Jul/2013,10/Jul/2013 P3,06/Jul/2013,15/Jul/2013 Ouput i want like this: P1,06/07/2013,09/07/2013,3days P2,06/07/2013,10/07/2013,4days P3,06/07/2013,15/07/2013,9days some one help is need for this please 回答1: This answer is heavily dependent on BSD date formatting available on a mac #!/usr/bin/awk -f BEGIN { FS=" " } { split(