gawk

AWK: Insert a row after each group of data

ぐ巨炮叔叔 提交于 2020-01-06 11:04:41
问题 I have a tab delimited csv file. The file is sorted by the column 6, which is the column that contains the key for each group. What I need is to insert a string after each group as a separator. Input: car camaleon queso cabra coche 531 cama leon lechuga dow click comedia clase tierno 531 falda camisa fiel rederdd black cama reloj visel 532 pila resto cena viento lamer viperest cash win 533 pale babe atun taza terron cabron fisgon dedo 533 one table deep black cama leona lechuga pies 534 blast

AWK: Insert a row after each group of data

和自甴很熟 提交于 2020-01-06 11:03:53
问题 I have a tab delimited csv file. The file is sorted by the column 6, which is the column that contains the key for each group. What I need is to insert a string after each group as a separator. Input: car camaleon queso cabra coche 531 cama leon lechuga dow click comedia clase tierno 531 falda camisa fiel rederdd black cama reloj visel 532 pila resto cena viento lamer viperest cash win 533 pale babe atun taza terron cabron fisgon dedo 533 one table deep black cama leona lechuga pies 534 blast

Convert n number of rows to columns repeatedly using awk

跟風遠走 提交于 2020-01-05 08:32:28
问题 My data is a large text file that consists of 12 rows repeating. It looks something like this: { 1 2 3 4 5 6 7 8 9 10 } repeating over and over. I want to turn every 12 rows into columns. so the data would look like this: { 1 2 3 4 5 6 7 8 9 10 } { 1 2 3 4 5 6 7 8 9 10 } { 1 2 3 4 5 6 7 8 9 10 } I have found some examples of how to convert all the rows to columns using awk: awk '{printf("%s ", $0)}' , but no examples of how to convert every 12 rows into columns and then repeat the process.

awk: create list of destination ports seen for each source IP from a bro log (conn.log)

孤人 提交于 2020-01-05 08:15:12
问题 I'm trying to solve a problem in awk as an exercise but I'm having trouble. I want awk (or gawk) to be able to print all unique destination ports for a particular source IP address. The source IP address is field 1 ($1) and the destination port is field 4 ($4). Cut for brevity: SourceIP SrcPort DstIP DstPort 192.168.1.195 59508 98.129.121.199 80 192.168.1.87 64802 192.168.1.2 53 10.1.1.1 41170 199.253.249.63 53 10.1.1.1 62281 204.14.233.9 443 I imagine you would store each Source IP as in

why isn't this awk script behaving as expected?

会有一股神秘感。 提交于 2020-01-05 04:50:13
问题 I have the following test script /^[^a-zA-Z0-9]/ { DATEd[$3] = $1 } END { print " \"data\": [" for (i = 0 ; i <= 5; i ++ ) { { print " [" i ", \"" DATEd[i] "\"],"} } print " ]" } And are reading from this text file 2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399 2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399 2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399 2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399 2011-01-22 22:12 P16A22_110114072915 22 1312

Using gawk in a batch file I am having trouble reformatting lines from format A to format B

对着背影说爱祢 提交于 2020-01-05 04:14:12
问题 I have a compiler which produces output like: >>> Warning <code> "c:\some\file\path\somefile.h" Line <num>(x,y): warning comment For example: >>> Warning 100 "c:\some\file\path\somefile.h" Line 10(5,7): you are missing a ( >>> Warning 101 "c:\some\file\path\file with space.h" Line 20(8,12): unexpected char a I need to get the into the format (for MSVS2013): <filename-without-quotes>(<line>,<column>) : <error|warning> <code>: <comment> e.g. using the first example from above: c:\some\file\path

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 substring a single character

纵饮孤独 提交于 2020-01-04 14:07:11
问题 Here is columns.txt aaa bbb 3 ccc ddd 2 eee fff 1 3 3 g 3 hhh i jjj 3 kkk ll 3 mm nn oo 3 I can find the line where second column starts with "b": awk '{if(substr($2,1,1)=="b") {print $0}}' columns.txt I can find the line where second column starts with "bb": awk '{if(substr($2,1,2)=="bb") {print $0}}' columns.txt Why oh why can't I find the line where the second character in the second column is "b"?: awk '{if(substr($2,2,2)=="b") {print $0}}' columns.txt awk -W version == GNU Awk 3.1.8 回答1:

Print second last column/field in awk

孤人 提交于 2019-12-28 03:20:10
问题 I want to print the second last column or field in awk. The number of fields is variable. I know that I should be able to use $NF but not sure how it can be used. And this does not seem to work: awk ' { print ( $NF-- ) } ' 回答1: awk '{print $(NF-1)}' Should work 回答2: Small addition to Chris Kannon' accepted answer: only print if there actually is a second last column. ( echo | awk 'NF && NF-1 { print ( $(NF-1) ) }' echo 1 | awk 'NF && NF-1 { print ( $(NF-1) ) }' echo 1 2 | awk 'NF && NF-1 {

Unable to remove carriage returns and line feeds in columns enclosed in double quotes [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-25 11:25:08
问题 This question already has an answer here : What's the most robust way to efficiently parse CSV using awk? (1 answer) Closed 2 years ago . I want to remove any non printable new line characters in the column data. I have enclosed all the columns with double quotes to delete the new line characters present in the column easily and to ignore the record delimiter after each end of line. Say,I have 4 columns seperated by comma and enclosed by quotes in a text file. I'm trying to remove \n and \r