gawk

awk keep if line contains “ example ”

自作多情 提交于 2019-12-25 08:54:34
问题 okay so I wish to keep lines containing several keywords, example of list: Name:email:username #registered Name2:email2:username2 Name3:email3:username3 #registered #subscribed #phonever Name4:email4:username4 #unconfirmed What I want to do is extract lines if they contain " #registered, #subscribed, #phonever example of output I want, Name:email:username #registered Name3:email3:username3 #registered #subscribed #phonever 回答1: With awk (use regex alternation operator, | , on a list of fixed

print from match & process several input files

纵饮孤独 提交于 2019-12-25 08:40:27
问题 when you scrutiny my questions from the past weeks you find I asked questions similar to this one. I had problems to ask in a demanded format since I did not really know where my problems came from. E. Morton tells me not to use range expression. Well, I do not know what they are excactly. I found in this forum many questions alike mine with working answers. Like: "How to print following line from a match" (e.g.) But all solutions I found stop working when I process more than one input file.

Use awk with two different delimiters to split and select columns

江枫思渺然 提交于 2019-12-25 02:44:13
问题 How can I tell gawk to use two different delimiters so that I can separate some columns, but select others using the tab-delimited format of my file? > cat broad_snps.tab chrsnpID rsID freq_bin snp_maf gene_count dist_nearest_gene_snpsnap dist_nearest_gene_snpsnap_protein_coding dist_nearest_gene dist_nearest_gene_located_within loci_upstream loci_downstream ID_nearest_gene_snpsnap ID_nearest_gene_snpsnap_protein_coding ID_nearest_gene ID_nearest_gene_located_within HGNC_nearest_gene_snpsnap

string pattaren-matching using awk

你。 提交于 2019-12-24 19:36:10
问题 (Couldn't come with any better title) I'm trying to convert a number of lines, like these: #define GENERIC_TYPE_METER_PULSE 0x30 /*Pulse Meter*/ #define SPECIFIC_TYPE_NOT_USED 0x00 /*Specific Device Class not used*/ ...... #define MFG_ID_WAYNE_DALTON 0x0008 //Wayne Dalton #define MFG_ID_WILSHINE_HOLDING_CO_LTD 0x012D //Wilshine Holding Co., Ltd #define MFG_ID_WIDOM 0x0149 //wiDom ...... #define COMMAND_CLASS_ALARM 0x71 #define COMMAND_CLASS_ALARM_V2 0x71 #define COMMAND_CLASS_NOTIFICATION_V3

javascript in gawk command

女生的网名这么多〃 提交于 2019-12-24 18:18:09
问题 i'm trying to understand some javascript in this gawk command: gawk 'function getip(rec) { n=split(rec,a,"\""); split(a[n-1],ip,","); return ip[1] } $10 ~ /302/ && $6 ~ /POST/ && $7 ~ /^\/sso\/[pl]fe\/(rs|ui)\/login/ { lfe_user_ip=getip($0); user_path[lfe_user_ip]=user_path[lfe_user_ip]"_login-302" } /\/sso\/pfe\/rs\/profile\/customer/ && $6 ~ /PUT/ { pfe_user_ip=getip($0); if (user_path[pfe_user_ip] ~ /_login-302/) { if ($10 ~ /200/) successful_redirect_conversion+=1; else failed_redirect

convert co-ordinate d-m-s to decimal degrees using awk

不问归期 提交于 2019-12-24 17:04:15
问题 My input is a tab-separated text file with lat long in D-M-S. I require output to be in decimal degrees I have code in php, but this is very slow to calculate. Can this be done quicker using awk? node name id latitude longitude seq nodex name1 70 N53-24-31.126 W6-20-46.982 59126 nodex name2 173 N53-20-28.885 W6-14-52.400 16190X nodex name3 173 N53-20-28.885 W6-14-52.400 16191T My PHP code with Formula: if ($dirLat == 'N') {$signLat = '+';} Else {$signLat = '-';} if ($dirLat == 'E') {$signLon

awk unmatched with blank file

*爱你&永不变心* 提交于 2019-12-24 04:01:17
问题 Recently I've encountered a strange behavioral problem with awk say I have two files one with blank file & the another is with populated data so let me apply a simple unmatched code awk -v var=0 'NR==FNR{a[$var]++;next} !($var in a)' file1 file2 say file1 & file 2 a b v it will return blank data where as it is supposed to return all the content in file 2. can someone explain me how to overcome this issue? 回答1: There isn't any data in file1 , so the overall record number never changes, so FNR

AWK how records and fields are executed and read

限于喜欢 提交于 2019-12-24 00:48:36
问题 I am getting the right result for the awk program below. But I dont understand how does AWK process lines of code for the below program : { for(i = 1; i <= NF; i++) { if (min[i]==""){ print "initial min " $i; min[i]=$i;} #line1 if (max[i]==""){ print "initial max " $i; max[i]=$i;} #line2 if ($i<min[i]) { print "New min " $i; min[i]=$i;} #line3 if ($i>max[i]) { print "New max " $i; max[i]=$i;} #line4 } } END { OFS="\t"; print "min","max"; for(i = 1; i <= NF; i++) { print min[i],max[i]; } }

Why can't I escape quote in gawk?

南笙酒味 提交于 2019-12-23 17:43:48
问题 I'm trying to do the following, but either I'm way too tired and can't think, or something weird is hapening with the escapes: scanimage -L | gawk '/N650U/ {print gensub("[\'`]", "", "g", $2)}' pipe bquote> 回答1: The idiom to do this is to create a variable which contains the single quote and then use that: scanimage -L | gawk '/N650U/ {print gensub(q"`", "", "g", $2)}' q="'" However, since you are using it in a character class, that is not going to work so you'll need to do this: scanimage -L

How to slice a variable into array indexes?

白昼怎懂夜的黑 提交于 2019-12-23 13:25:33
问题 There is this typical problem: given a list of values, check if they are present in an array. In awk , the trick val in array does work pretty well. Hence, the typical idea is to store all the data in an array and then keep doing the check. For example, this will print all lines in which the first column value is present in the array: awk 'BEGIN {<<initialize the array>>} $1 in array_var' file However, it is initializing the array takes some time because val in array checks if the index val