Search Results

Search: Posts Made By: Geneanalyst
3,855
Posted By Don Cragun
Hi bakunin, It will with a recent ksh (such as...
Hi bakunin,
It will with a recent ksh (such as version 93u+). It might with a recent bash, but not with bash version 3.26 (the version included with the latest macOS release) where the following...
3,855
Posted By Don Cragun
What you have looks like it would try to change a...
What you have looks like it would try to change a file named FILE_1000G.vcf to instead have the literal name $filename_1000G.vcf assuming that the only file in the directory where you run this script...
1,571
Posted By Chubler_XL
Are you sure you have the code as posted? The...
Are you sure you have the code as posted? The solution I presented shouldn't be able to print more lines than is in file2. I suspect you don't have and END { block and the for loop is executing for...
1,571
Posted By Chubler_XL
If vgersh99's solution if matching lines are less...
If vgersh99's solution if matching lines are less than 30 lines apart some lines are printed multiple times (overlapping regions).

Try this modification:

BEGIN {
if(!ba) ba=2
}
FNR == NR {...
1,571
Posted By vgersh99
something along these lines: default 2 lines...
something along these lines:
default 2 lines before/after
awk -f gene.awk file2.txt file1.txt
or 30 lines before/after
awk -v ba=30 -f gene.awk file2.txt file1.txt
where gene.awk is:

BEGIN...
1,401
Posted By Corona688
I note that none of the data you posted looks...
I note that none of the data you posted looks like it came from strictly tab-separated files. I suspect rogue spaces and/or carriage returns in your data.

From your example file1 and file2 I get...
1,401
Posted By RudiC
How about, hoping that any invisible surprises...
How about, hoping that any invisible surprises like the ones corona688 mentioned will have been taken care of, and untested, from a windows machine, so bear with me:


awk -F "\t" 'NR == FNR...
1,401
Posted By jim mcnamara
What Rudi & Corona are saying: UNIX text files...
What Rudi & Corona are saying: UNIX text files have different carriage control characters from windows text files - like tab delimited Excel output.

cleanup windows files == dos2unix command:
...
1,340
Posted By vgersh99
awk -F '\t' ' # when FNR==NR (only true for the...
awk -F '\t' '
# when FNR==NR (only true for the FIRST file on cli),
# populate array f3 indexed by $1 (first field) in the file (file3)
# next - advance to the next input record/line in file3...
1,340
Posted By vgersh99
awk -F '\t' 'FNR==NR {f3[$1];next} $1 in f3'...
awk -F '\t' 'FNR==NR {f3[$1];next} $1 in f3' OFS="\t" file3 file1.txt > file2.txt
1,340
Posted By vgersh99
please provide the output of cat -vet file1.txt...
please provide the output of cat -vet file1.txt using code tags.
With the properly formatted file1.txt (tab-delimited fields), I get:

awk -F '\t' 'FNR==NR {f3[$1];next} $1 in f3' OFS="\t"...
1,382
Posted By RudiC
Would awk 'NR == FNR {REP[$1,$4] = $2; next}...
Would
awk 'NR == FNR {REP[$1,$4] = $2; next} ($1,$4) in REP {$2 = REP[$1,$4]; CNT++} 1; END {print CNT}' OFS="\t" file2 file1do what you need?
1,560
Posted By RavinderSingh13
Hello Geneanalyst, If your Input_file is...
Hello Geneanalyst,

If your Input_file is same as shown samples then following may help you on same.

awk 'FNR==NR&&FNR>1{a[$1]=$NF;next} FNR>1{if(a[$1]){$NF=$(NF-1)=""} else {$(NF-1)=OFS $(NF-1)...
1,560
Posted By RudiC
Try awk 'NR == FNR {REP[$1] = $4; next} $1 in...
Try
awk 'NR == FNR {REP[$1] = $4; next} $1 in REP && FNR > 1 {$4 = substr (REP[$1], 1, 1); $5 = substr ( REP[$1], 2, 2); CNT++} 1; END {print CNT}' OFS="\t" file2 file1
1,560
Posted By RavinderSingh13
Hello Geneanalys, Could you please try...
Hello Geneanalys,

Could you please try following and let me know if this helps you. (tested with GNU awk)

awk 'FNR==NR{num=split($NF,array,"");for(i=1;i<=num;i++){val=val?val OFS...
1,560
Posted By RudiC
Try awk 'NR == FNR {REP[$1] = $4; next} $1 in...
Try
awk 'NR == FNR {REP[$1] = $4; next} $1 in REP && FNR > 1 {$4 = substr (REP[$1], 1, 1); $5 = substr ( REP[$1], 2, 1)} 1' OFS="\t" file2 file1
rsid chromosome position allele1 allele2...
1,560
Posted By Scrutinizer
Hi, try: awk ' NR==1 { next } ...
Hi, try:
awk '
NR==1 {
next
}

NR==FNR {
A[$1]=substr($4,1,1)
B[$1]=substr($4,2)
next
}

$1 in A {
$4=A[$1]
$5=B[$1]
}
1
' OFS='\t' IN2 IN1
1,796
Posted By drl
Hi. I like awk solutions. However, I also...
Hi.

I like awk solutions. However, I also like packaged solutions. In this case GNU datamash can do the grouping and summing with:
datamash -g 1 sum 2,3
which will sum fields 2 and 3 for items...
1,796
Posted By Don Cragun
Here is a copy of RudiC's code with comments...
Here is a copy of RudiC's code with comments added describing what each section of code is doing:
awk ' # Invoke awk and start script to be run by awk.
BEGIN {# Before any lines are read from any...
1,796
Posted By RudiC
Try also awk ' BEGIN {FMT =...
Try also
awk '
BEGIN {FMT = "%-13s%-17s%-17s\n"
printf FMT, "SAMPLE", "TOTAL DERIVED", "TOTAL ANCESTRAL"
}
FNR > 1 {SEQ[FNR] = $1
SUMD[$1] += $2
SUMA[$1]...
1,796
Posted By Scrutinizer
Hi, try: awk '{split($0,F)} getline<f>0 &&...
Hi, try:
awk '{split($0,F)} getline<f>0 && NR>1{$2+=F[2]; $3+=F[3]}1' f=array1 array2

Or you could try an approach like this which should work with 2 or more arrays:
awk '
FNR==1 {
...
1,796
Posted By RavinderSingh13
Hello Geneanalyst, Could you please try...
Hello Geneanalyst,

Could you please try following and let me know if this helps you.


awk 'BEGIN{print "SAMPLE TOTAL DERIVED TOTAL ANCESTRAL"} FNR==NR{a[$1]=$2;b[$1]=$3;next}...
1,274
Posted By RudiC
Based on your sample, where there is NO other...
Based on your sample, where there is NO other field containing "a","c","g", or "t", this could work:
sed 'y/acgt/ACGT/' file
1,274
Posted By rdrtx1
awk ' { if (str ~ ":" $6 ":") $6=toupper($6);...
awk '
{
if (str ~ ":" $6 ":") $6=toupper($6);
print $0;
}' str=":a:c:g:t:" datafile
or
awk '$6=toupper($6)' datafile
1,274
Posted By Yoda
Note that = is an assignment operator. It assigns...
Note that = is an assignment operator. It assigns the value of right side expression to left side.

But == is an equal to operator. It compares the value of both sides. Hence you have to use == in...
Showing results 1 to 25 of 44

 
All times are GMT -4. The time now is 02:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy