Search Results

Search: Posts Made By: yuejian
1,203
Posted By MadeInGermany
Here is a solution that is slow but uses little...
Here is a solution that is slow but uses little memory.

#!/bin/sh
while read line
do
awk '($1==search) {print; exit 1}' search="$line" file_B && echo "N/A"
done < file_A
813
Posted By vgersh99
awk -v RS="" '{print gsub(/[>]/, "&")}'...
awk -v RS="" '{print gsub(/[>]/, "&")}' myFile
1,219
Posted By MadeInGermany
A nice brain teaser! The following keeps the...
A nice brain teaser!
The following keeps the order of columns in file1:
awk '
BEGIN {FS="\t"}
FNR==NR {Ctext[$1]; next}
FNR==1 {
for (i=NF;i>=1;i--) if ($i in Ctext) {C[i]}
}
{
for...
1,219
Posted By bakunin
This is all well and we try to help as much as we...
This is all well and we try to help as much as we can. The reason why most of us insist that a genuine effort in solving the problem by oneself is made is because we try to help you to help yourself....
1,219
Posted By RudiC
No attempts from your side? Pity... Tryawk ...
No attempts from your side? Pity...

Tryawk 'FNR==NR {H[NR]=$1; MX=NR; next}
FNR==1 {for (j=1; j<=MX; j++) for (i=1; i<=NF; i++) if (H[j]==$i) C[j]=i}
...
775
Posted By Aia
I don't know if I missed this part or it was...
I don't know if I missed this part or it was edited:

I am assuming that your file, actually, looks something like:

CR387793 -0.8
CR387793 -5.5
CR387794 -5.3
CR387795 -0.9
CR387796
AR388755...
1,600
Posted By DGPickett
Shell can do this. If I was more elegant, the...
Shell can do this. If I was more elegant, the explicit 123 bits would be array references in a loop.(
lim=3 IFS=$IFS')(' v1ct=0 v2ct=0 v3ct=0 v1last=x v2last=x v3last=x

while read x1 v1 x2 v2 x3...
1,600
Posted By RudiC
Try this, tested from n=1 till n=4:awk 'BEGIN...
Try this, tested from n=1 till n=4:awk 'BEGIN {MAX[1]=MAX[2]=MAX[3]=-1E100}
{for (i=1; i<=3; i++) {TX=$i
gsub (/^[^(]*\(|\)/, "", TX)...
1,111
Posted By RudiC
Not sure I understood your spec. Tryawk ...
Not sure I understood your spec. Tryawk 'FNR==NR {T[$0];next}
{split ($2, S, "[|.]")}
$2 in T {print $2 "\t(" $4 ")"}
S[4] in T ...
775
Posted By RavinderSingh13
Hello yuejian, Following may help if there...
Hello yuejian,

Following may help if there is a column whose 2nd field is empty. Let's say following is input file.


cat Input_file
CR387793 -0.8
CR387793 -5.5
CR387794 -5.3
CR387795...
775
Posted By Aia
awk '{A[$1]+=$2;++D[$1]} END{ for (n in A){print...
awk '{A[$1]+=$2;++D[$1]} END{ for (n in A){print n, A[n]/D[n]}}' file

CR387793 -3.15
CR387794 -5.3
CR387795 -0.9
AR388755 1.76667

Notice that the average of
AR388755 -3.0
AR388755 3.8...
1,296
Posted By Scrutinizer
Or, same idea: awk 'NR==FNR{A[$1]=$2; next} $1...
Or, same idea:
awk 'NR==FNR{A[$1]=$2; next} $1 in A{$1=A[$1]}1' OFS='\t' file1 file2
1,296
Posted By RudiC
Try awk 'NR==FNR{T[$1]=$2;next} $1 in T {print...
Try awk 'NR==FNR{T[$1]=$2;next} $1 in T {print T[$1], $2; next} {print}' OFS="\t" file1 file2
Z A
Y B
dd C
X D
Y E
1,424
Posted By Akshay Hegde
Try grep -Fxf file1 file2 NM_001277933 ...
Try

grep -Fxf file1 file2
NM_001277933
NM_001277927


awk 'FNR==NR{A[$0];next}$0 in A' file1 file2

comm -12 <( sort file1 ) <( sort file2 )
1,424
Posted By RudiC
It is not, but "GALGA25_CL1" is. That's what is...
It is not, but "GALGA25_CL1" is. That's what is called "false positives". Akshay Hegde already provided you with the -x (exact whole line match) option.
1,332
Posted By MadeInGermany
While the idea sounds a bit strange, you can make...
While the idea sounds a bit strange, you can make it more robust like this:
ls | while IFS="" read -r file
do
read hasline1 < "$file"
if [ "$hasline1" != "$file" ]
then
(echo "$file";...
1,755
Posted By DGPickett
NOt very structured data, but what the hey!...
NOt very structured data, but what the hey! Middle file could be reworked into a shell case statement as a dynamic psart of a parent script. Using shell 'while read a b c' command, the three fields...
1,755
Posted By RudiC
Try (untested):awk 'NR==FNR{T[$1];next}{for (i in...
Try (untested):awk 'NR==FNR{T[$1];next}{for (i in T) if ($0 ~ i) T[i]+=$(NF-1)} END {for (i in T) print i, T[i]}' file2 file1| sort -k2nIf you absolutely need the parentheses in the output, add them...
1,755
Posted By Don Cragun
With your new input file format, the following...
With your new input file format, the following seems to work:
awk '
FNR == NR {
key[$1]
next
}
{ for(k in key)
if(index($2, k))
...
2,111
Posted By Corona688
awk is often used for this as so: awk...
awk is often used for this as so:

awk 'NR==FNR { A[$1]=$2 ; next } ; $1 in A { $1=A[$1] } 1' file1 file2

The NR==FNR section loads all lines in file1 into the array A as A["aa"]="M", etc. The...
Showing results 1 to 20 of 20

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