nawk

AWK is it possible to read a time field and use it for sorting?

淺唱寂寞╮ 提交于 2020-01-05 03:06:30
问题 I have two files and I need to sort and merge the rows based on the time column: File A: "2014-02-26 16:03:04" "Login Success|isNoSession=false" id=csr,ou=user,dc=openam,dc=forgerock,dc=org 7efb2f0e035a0e3d01 10.17.174.30 INFO dc=openam,dc=forgerock,dc=org "cn=dsameuser,ou=DSAME Users,dc=openam,dc=forgerock,dc=org" AUTHENTICATION-100 DataStore "Not Available" 10.17.174.30 File B: "2014-02-26 16:02:27" "Login Failed" dennis "Not Available" 10.17.174.30 INFO dc=openam,dc=forgerock,dc=org "cn

awk set elements in array

对着背影说爱祢 提交于 2019-12-23 02:52:18
问题 I have a large .csv file to to process and my elements are arranged randomly like this: xxxxxx,xx, MLOCAL , MREMOTE , 33222 , 56 , 22/10/2012 , 18/10/2012 xxxxxx,xx, MREMOTE , MLOCAL , 33222 , 56 , 22/10/2012 , 18/10/2012 xxxxxx,xx, MLOCAL , 341993 , 22/10/2012 xxxxxx,xx, MREMOTE , 9356828 , 08/10/2012 xxxxxx,xx, LOCAL , REMOTE , 19316 , 15253 , 22/10/2012 , 22/10/2012 xxxxxx,xx, REMOTE , LOCAL , 1865871 , 383666 , 22/10/2012 , 22/10/2012 xxxxxx,xx, REMOTE , 1180306134 , 19/10/2012 where

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(

trying to get the results using awk

血红的双手。 提交于 2019-12-12 06:47:44
问题 I've a file named xyz.csv which are comma separated.I'm trying to get the output where the 2nd column should have value "01", 50th column as "ABC" and the content of 80th column using nawk? 回答1: Could you please try following and let me know if this helps. nawk -F"," '$2=="01" && $50 == "ABC"{print $80}' xyz.csv OR If you are looking for 50th and 80th field's value should be ABC and you want to print current line then following may help you in same. nawk -F"," '$2=="01" && $50 == "ABC" && $80

search (e.g. awk, grep, sed) for string, then look for X lines above and another string below

前提是你 提交于 2019-12-11 07:03:21
问题 I need to be able to search for a string (lets use 4320101), print 20 lines above the string and print after this until it finds the string For example: Random text I do not want or blank line 16 Apr 2013 00:14:15 id="4320101" </eventUpdate> Random text I do not want or blank line I just want the following result outputted to a file: 16 Apr 2013 00:14:15 id="4320101" </eventUpdate> There are multiple examples of these groups of text in a file that I want. I tried using this below: cat

How to handle 3 files with awk?

限于喜欢 提交于 2019-12-04 13:50:11
问题 Ok, so after spending 2 days, I am not able solve it and I am almost out of time now. It might be a very silly question, so please bear with me. My awk script does something like this: BEGIN{ n=50; i=n; } FNR==NR { # Read file-1, which has just 1 column ids[$1]=int(i++/n); next } { # Read file-2 which has 4 columns # Do something next } END {...} It works fine. But now I want to extend it to read 3 files. Let's say, instead of hard-coding the value of "n", I need to read a properties file and

UNIX shell script and escaping quotes for AWK script

空扰寡人 提交于 2019-12-04 06:20:21
问题 I have a UNIX script that has nawk block inside it (This is just a part of the UNIX and NAWK script. It has many more logic and the below code should definitely be in nawk) This block that reads a lookup value for Country ISO code from a file that has country and country code values and I face an issue whenever there is a bracket in the country name () or a single apostrope ' Sample values CIV@COTE D'IVOIRE COD@CONGO, Democratic Republic of (was Zaire) Can you pls help me overcome these 2

How to handle 3 files with awk?

夙愿已清 提交于 2019-12-03 08:46:18
Ok, so after spending 2 days, I am not able solve it and I am almost out of time now. It might be a very silly question, so please bear with me. My awk script does something like this: BEGIN{ n=50; i=n; } FNR==NR { # Read file-1, which has just 1 column ids[$1]=int(i++/n); next } { # Read file-2 which has 4 columns # Do something next } END {...} It works fine. But now I want to extend it to read 3 files. Let's say, instead of hard-coding the value of "n", I need to read a properties file and set value of "n" from that. I found this question and have tried something like this: BEGIN{ n=0; i=0;

Transpose rows into column in unix

风流意气都作罢 提交于 2019-12-03 08:37:31
I have input file which is given below Input file 10,9:11/61432568509 118,1:/20130810014023 46,440:4/GTEL 10,9:11/61432568509 118,1:/20130810014023 46,440:4/GTEL Output which i am looking for. 10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL 10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL I have tried with awk command, but i am not getting desired output. can anyone help me in this? awk -F"" '{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}' inputfile devnull Using awk : $ awk 'ORS=(NR%3==0)?"\n":","' inputfile 10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL 10,9:11

UNIX shell script and escaping quotes for AWK script

橙三吉。 提交于 2019-12-02 12:27:11
I have a UNIX script that has nawk block inside it (This is just a part of the UNIX and NAWK script. It has many more logic and the below code should definitely be in nawk) This block that reads a lookup value for Country ISO code from a file that has country and country code values and I face an issue whenever there is a bracket in the country name () or a single apostrope ' Sample values CIV@COTE D'IVOIRE COD@CONGO, Democratic Republic of (was Zaire) Can you pls help me overcome these 2 issues.for a single apostrope can I have it removed from the string or is there any way I can just fine