awk

AWK: Comparing two different columns in two files

不羁的心 提交于 2021-02-07 07:19:45
问题 I have these two files File1: 9 8 6 8 5 2 2 1 7 0 6 1 3 2 3 4 4 6 File2: (which has over 4 million lines) MN 1 0 JK 2 0 AL 3 90 CA 4 83 MK 5 54 HI 6 490 I want to compare field 6 of file1, and compare field 2 of file 2. If they match, then put field 3 of file2 at the end of file1 I've looked at other solutions but I can't get it to work correctly. Desired output: 9 8 6 8 5 2 0 2 1 7 0 6 1 0 3 2 3 4 4 6 490 My attempt: awk 'NR==FNR{a[$2]=$2;next}a[$6]{print $0,a[$6]}' file2 file1 program just

Parallel processing in awk?

故事扮演 提交于 2021-02-07 07:00:23
问题 Awk processes the files line by line. Assuming each line operation has no dependency on other lines, is there any way to make awk process multiple lines at a time in parallel? Is there any other text processing tool which automatically exploits parallelism and processes the data quicker ? 回答1: The only awk implementation that was attempting to provide a parallel implementation of awk was parallel-awk but it looks like the project is dead now. Otherwise, one way to parallelize awk is be to

remove all lines in a file containing a string from another file

╄→гoц情女王★ 提交于 2021-02-07 04:31:05
问题 I'd like to remove all the lines of a file based on matching a string from another file. This is what I have used but it only deletes some: grep -vFf to_delete.csv inputfile.csv > output.csv Here are sample lines from my input file (inputfile.csv): Ata,Aqu,Ama3,Abe,0.053475,0.025,0.1,0.11275,0.1,0.15,0.83377 Ata135,Aru2,Aba301,A29,0.055525,0.025,0.1,0.082825,0.075,0.125 Ata135,Atb,Aca,Am54,0.14695,0.1,0.2,0.05255,0.025,0.075,0.8005, Adc,Aru7,Ama301,Agr84,0.002075,0,0.025,0.240075,0.2,0. My

How to check the type of an awk variable?

一世执手 提交于 2021-02-07 04:20:10
问题 The Beta release of gawk 4.2.0, available in http://www.skeeve.com/gawk/gawk-4.1.65.tar.gz is a major release, with many significant new features . I previously asked about What is the behaviour of FS = " " in GNU Awk 4.2?, and now I noticed the brand new typeof() function to deprecate isarray(): Changes from 4.1.4 to 4.2.0 The new typeof() function can be used to indicate if a variable or array element is an array, regexp, string or number. The isarray() function is deprecated in favor of

How to check the type of an awk variable?

陌路散爱 提交于 2021-02-07 04:18:48
问题 The Beta release of gawk 4.2.0, available in http://www.skeeve.com/gawk/gawk-4.1.65.tar.gz is a major release, with many significant new features . I previously asked about What is the behaviour of FS = " " in GNU Awk 4.2?, and now I noticed the brand new typeof() function to deprecate isarray(): Changes from 4.1.4 to 4.2.0 The new typeof() function can be used to indicate if a variable or array element is an array, regexp, string or number. The isarray() function is deprecated in favor of

awk print matching line and line before the matched

六月ゝ 毕业季﹏ 提交于 2021-02-07 03:18:15
问题 Following is what I am trying to do using awk. Get the line that matches the regex and the line immediately before the matched and print. I can get the line that matched the regex but not the line immediately before that: awk '{if ($0!~/^CGCGGCTGCTGG/) print $0}' 回答1: In this case you could easily solve it with grep: grep -B1 foo file However, if you need to to use awk: awk '/foo/{if (a && a !~ /foo/) print a; print} {a=$0}' file 回答2: /abc/{if(a!="")print a;print;a="";next} {a=$0} 回答3: use

awk print matching line and line before the matched

时光总嘲笑我的痴心妄想 提交于 2021-02-07 03:05:57
问题 Following is what I am trying to do using awk. Get the line that matches the regex and the line immediately before the matched and print. I can get the line that matched the regex but not the line immediately before that: awk '{if ($0!~/^CGCGGCTGCTGG/) print $0}' 回答1: In this case you could easily solve it with grep: grep -B1 foo file However, if you need to to use awk: awk '/foo/{if (a && a !~ /foo/) print a; print} {a=$0}' file 回答2: /abc/{if(a!="")print a;print;a="";next} {a=$0} 回答3: use

awk print matching line and line before the matched

Deadly 提交于 2021-02-07 03:05:23
问题 Following is what I am trying to do using awk. Get the line that matches the regex and the line immediately before the matched and print. I can get the line that matched the regex but not the line immediately before that: awk '{if ($0!~/^CGCGGCTGCTGG/) print $0}' 回答1: In this case you could easily solve it with grep: grep -B1 foo file However, if you need to to use awk: awk '/foo/{if (a && a !~ /foo/) print a; print} {a=$0}' file 回答2: /abc/{if(a!="")print a;print;a="";next} {a=$0} 回答3: use

First character of a variable in a shell script to uppercase?

这一生的挚爱 提交于 2021-02-06 15:29:33
问题 I have a shell script that starts unit tests for modules. I need the name of the module in all lowercase and with the first character uppercase. So far I have been doing it like this: #!/bin/sh -x # z.B. getbrowser strModuleToTest=$1 # g strModuleToTestUppercaseFirstletter=${strModuleToTest:0:1} # etbrowser strModuleToTestUppercaseLastletters=${strModuleToTest:1} # g -> G strModuleToTestUppercaseFirstletter="${strModuleToTestUppercaseFirstletter/a/A}" strModuleToTestUppercaseFirstletter="$

First character of a variable in a shell script to uppercase?

蓝咒 提交于 2021-02-06 15:26:53
问题 I have a shell script that starts unit tests for modules. I need the name of the module in all lowercase and with the first character uppercase. So far I have been doing it like this: #!/bin/sh -x # z.B. getbrowser strModuleToTest=$1 # g strModuleToTestUppercaseFirstletter=${strModuleToTest:0:1} # etbrowser strModuleToTestUppercaseLastletters=${strModuleToTest:1} # g -> G strModuleToTestUppercaseFirstletter="${strModuleToTestUppercaseFirstletter/a/A}" strModuleToTestUppercaseFirstletter="$