awk

Change text in argument for xargs (or GNU Parallel)

£可爱£侵袭症+ 提交于 2020-01-04 09:27:10
问题 I have a program that I can run in two ways: single-end or paired-end mode. Here's the syntax: program <output-directory-name> <input1> [input2] Where the output directory and at least one input is required. If I wanted to run this on three files, say, sample A, B, and C, I would use something like find with xargs or parallel: user@host:~/single$ ls sampleA.txt sampleB.txt sampleC.txt user@host:~/single$ find . -name "sample*" | xargs -i echo program {}-out {} program ./sampleA.txt-out .

Change text in argument for xargs (or GNU Parallel)

限于喜欢 提交于 2020-01-04 09:27:03
问题 I have a program that I can run in two ways: single-end or paired-end mode. Here's the syntax: program <output-directory-name> <input1> [input2] Where the output directory and at least one input is required. If I wanted to run this on three files, say, sample A, B, and C, I would use something like find with xargs or parallel: user@host:~/single$ ls sampleA.txt sampleB.txt sampleC.txt user@host:~/single$ find . -name "sample*" | xargs -i echo program {}-out {} program ./sampleA.txt-out .

How can I collapse this bash command line into an awk statement?

谁都会走 提交于 2020-01-04 09:16:08
问题 I've created an awk script and use it like this: # grep -E "[PM][IP][DO][:S]" file.txt | awk-script How can I modify the awk script to include the effort of the grep command (which is searching for either "PID:" or "MPOS"? awk-script is: #!/usr/bin/awk -f /Sleeve/ { printf("%8d, %7d, %7.2f, %7.2f, %7.2f\n", $5, $6, $7, $30, $31) } /Ambient/ { printf("%8d, %7d,,,, %7.2f, %7.2f\n", $5, $6, $7, $8) } /MPOS:/ { printf("%8d, %7d,,,,,, %5d, %5d\n", $4, $5, $2, $3) } 回答1: If you just want to search

Awk Comparsion in multiple files

混江龙づ霸主 提交于 2020-01-04 07:01:51
问题 I have 2 files: file1 : 1,apple 2,mango 3,banana 44,orange file2 : 1,apple 22, 31,xyz 2,man 3,banana 44,oran 44,orange I need to find the differences from both the files using column 1 and checking column 2. I don't want to use $0 as its printing the lines which of 1st file which are not present in file2 too. Result output should be printed in file3 as : 2,mango,man 44,orange,oran Mango is from file1 (column 2) and man is from file2 (column2) 回答1: Slightly different awk: $ awk 'BEGIN{FS=OFS="

Awk Comparsion in multiple files

别来无恙 提交于 2020-01-04 07:01:11
问题 I have 2 files: file1 : 1,apple 2,mango 3,banana 44,orange file2 : 1,apple 22, 31,xyz 2,man 3,banana 44,oran 44,orange I need to find the differences from both the files using column 1 and checking column 2. I don't want to use $0 as its printing the lines which of 1st file which are not present in file2 too. Result output should be printed in file3 as : 2,mango,man 44,orange,oran Mango is from file1 (column 2) and man is from file2 (column2) 回答1: Slightly different awk: $ awk 'BEGIN{FS=OFS="

awk, calculate the average for different interval of time

戏子无情 提交于 2020-01-04 06:24:13
问题 can anybody teach me how to calculate the average for between the difference of time? for example 412.00 560.00 0 0 361.00 455.00 561.00 0 0 0 0 0 0 237.00 581.00 425.00 464.00 426.00 520.00 0 0 the normal case, they do the sum of all of those number divide by total set of number sum/NR the challenge here the number of column is dynamic, which mean not all of the line have the same number column to calculate the average , example we have this : 361.00 455.00 561.00 so the calculation : ((455

Using `awk` to print number of lines in file in the BEGIN section

一曲冷凌霜 提交于 2020-01-04 04:31:49
问题 I am trying to write an awk script and before anything is done tell the user how many lines are in the file. I know how to do this in the END section but unable to do so in the BEGIN section. I have searched SE and Google but have only found a half dozen ways to do this in the END section or as part of a bash script, not how to do it before any processing has taken place at all. I was hoping for something like the following: #!/usr/bin/awk -f BEGIN{ print "There are a total of " **TOTAL LINES

BASH - Shuffle characters in strings from file

只谈情不闲聊 提交于 2020-01-04 04:11:11
问题 I have a file ( filename.txt ) with the following structure: >line1 ABC >line2 DEF >line3 GHI >line4 JKL I would like to shuffle the characters in the strings that do not start wit > . The output would (for example) look like the following: >line1 BCA >line2 DFE >line3 IHG >line4 KLJ This is what I tried to shuffle the characters in a string: sed 's/./&\n/' | shuf | tr -d "\n" . It looks like it works but it does not take into account newlines. Moreover it executes the command on all data and

awk/sed/shell to merge/concatenate data

若如初见. 提交于 2020-01-03 20:23:11
问题 Trying to merge some data that I have. The input would look like so: foo bar foo baz boo abc def abc ghi And I would like the output to look like: foo bar baz boo abc def ghi I have some ideas using some arrays in a shell script, but I was looking for a more elegant or quicker solution. 回答1: How about join? file="file" join -a1 -a2 <(sort "$file" | sed -n 1~2p) <(sort "$file" | sed -n 2~2p) The seds there are just splitting the file on odd and even lines 回答2: While pixelbeat's answer works, I

tips'n'tricks in awk [closed]

萝らか妹 提交于 2020-01-03 17:56:28
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm looking for caveats, tips'n'tricks etc. for awk. For example: awk '$9=="404"{a[$7]++}END{for(i in a)print a[i],i}' access.log|less