Search Results

Search: Posts Made By: polsum
1,564
Posted By CarloM
awk 'NR==FNR{a[$1]=$2;next}{for (i in a)...
awk 'NR==FNR{a[$1]=$2;next}{for (i in a) gsub(i,a[i]); print }' file1 file2
1,564
Posted By bartus11
Try:awk...
Try:awk 'NR==FNR{a[$1]=$2;next}!(FNR%3){n=split($0,x,"");$0="";for (i=1;i<=n;i++)$0=$0""a[x[i]]}1' file1 file2
1,449
Posted By bartus11
Try: perl -p0e...
Try: perl -p0e 's/^(\w)(.*)(\w+)\n\1.*?(\w+)$/\1\2\3_\4/mg' file
1,826
Posted By bartus11
Try this website: The AWK Manual - Table of...
Try this website: The AWK Manual - Table of Contents (http://www.staff.science.uu.nl/~oostr102/docs/nawk/nawk_toc.html)
1,826
Posted By bartus11
Try: awk 'NR==FNR{for (i=3;i<=NF;i++)...
Try: awk 'NR==FNR{for (i=3;i<=NF;i++) a[$1"-"i]+=$i;next}FNR>1{for (i=3;i<=NF;i++) $i=sprintf ("%.2f",($i*100)/a[$1"-"i])}1' file file
Notice that you have to specify filename twice.
1,870
Posted By Scrutinizer
Try: awk 'NR==1 || $2==$3 && $3==$4 && $5==$6...
Try:
awk 'NR==1 || $2==$3 && $3==$4 && $5==$6 && $6==$7' infile
-or less robust-
sed -n '1p;/[^ ]*\( [^ ]*\)\1\1\( [^ ]*\)\2\2/p' infile
2,341
Posted By bartus11
Try: awk '$2>M[$5]{M[$5]=$2;a[$5]=$0}END{for (i...
Try: awk '$2>M[$5]{M[$5]=$2;a[$5]=$0}END{for (i in a) print a[i]}' file
2,753
Posted By Franklin52
awk 'NR==FNR{a[$1]=1;next} a[$5]{if($2 >...
awk 'NR==FNR{a[$1]=1;next} a[$5]{if($2 > a[$5]){a[$5]=$2;b[$5]=$0}} END{for(i in b)print b[i]}' file1 file2
2,753
Posted By Franklin52
Try this: awk 'NR==FNR{a[$1]=1;next}($1 in a)...
Try this:
awk 'NR==FNR{a[$1]=1;next}($1 in a) && $2 > a[$1]{a[$1]=$2}END{for(i in a)print i, a[i]}' file1 file2
2,522
Posted By ahamed101
There are so many posts in this forum with the...
There are so many posts in this forum with the same query...

awk 'NR==FNR{_[$3]++;next}!_[$3]' file2 file1
--ahamed
2,229
Posted By birei
Hi polsum, Try (using flip-flop in perl): ...
Hi polsum,

Try (using flip-flop in perl):

$ perl -wlne 'if ( $c = (m|SQ|..m|//|) ) { next unless $c == 1 || $c =~ m/E0$/ } print' infile
SQ kkk m99029 wwwAV
//
AS
DS
SQ ooo l9909 qqqqa
//...
2,229
Posted By Corona688
another way using awk: awk '/SQ/ { P=1;...
another way using awk:

awk '/SQ/ { P=1; print }; /\/\// { P=0; print }; !P' filename
4,639
Posted By uniqme
cat f1.txt a 455 b 443 c 6655 d 554 ...
cat f1.txt

a 455
b 443
c 6655
d 554
e 6

$ cat f2.txt

a 56
b 5
x 678

awk '$0 !~ /#/{arr[$1]=arr[$1] " " $2}END{for(i in arr)print i,arr[i]}' f1.txt f2.txt

x 678
a 455 56
b ...
4,639
Posted By yinyuemi
if you have multiple files,please try this:awk...
if you have multiple files,please try this:awk '{a[ARGIND" "$1]=$2;b[$1];t=ARGIND}END{for(i in b){printf i ;for(j=1;j<=t;j++)printf FS (length(a[j" "i])?a[j" "i]:"0");print ""}}' file1 file2 file1...
4,639
Posted By yinyuemi
awk '{if($1 in a){sub("0"...
awk '{if($1 in a){sub("0" FS,"",a[$1]);a[$1]=a[$1] FS $2}else{a[$1]="0" FS $2}}END{for(i in a)print i,a[i]}' file1 file2
7,197
Posted By yazu
Assuming you don't want lines when the first...
Assuming you don't want lines when the first field repeats N times:
awk -v N=10 '
$1 != prev {
if (c != N) for (i=1; i<=c; i++) print a[i]
c = 0
}
{
a[++c] = $0;
prev = $1;
} ...
7,197
Posted By birei
Hi polsum, Here you have another 'perl'...
Hi polsum,

Here you have another 'perl' solution:

$ cat File1
13 18 1 + chromosome 1, 122638287 AGAGTATGGTCGCGGTTG
13 18 1 + chromosome 1, 128904080 AGAGTATGGTCGCGGTTG
13 18 1 - chromosome...
7,197
Posted By rangarasan
PERL
Hi,

Try this code,


#! /usr/local/bin/perl
open(FILE,"<File1") or die("unable to open file");
my @mContent = <FILE>;
my %mFinal = ();
foreach ( @mContent )
{
my $mLine = $_;
...
2,232
Posted By durden_tyler
$ $ $ cat data.txt 2 7 18 ggcgt anna 2 9...
$
$
$ cat data.txt
2 7 18 ggcgt anna
2 9 24 kosss Brenham
4 7 18 hhcjd jenny
3 8 21 kkok bush
2 7 18 hhchc sam
0 8 21 jjdhs sam
3 7 18 hhdjcc ross
$
$
$ perl -lne 'push @x, $_;
...
1,495
Posted By bartus11
#!/usr/bin/perl open A, "$ARGV[1]"; open B,...
#!/usr/bin/perl
open A, "$ARGV[1]";
open B, "$ARGV[0]";
chomp(@x=<A>);
local $/;
$_=<B>;
for $x (@x){
s/$x.*//g;
}
print;
Run it like this: ./script.pl file1 file2
4,142
Posted By g.pi
@polsun, let me make a suggestion, if I may. ...
@polsun, let me make a suggestion, if I may. Since you are learning something new, I suggest that you learn perl instead. Perl can pretty much do what awk can (IMHO) and lots more. It is not...
4,518
Posted By alister
What's the delimiter in file 2? The pipe, "|" ? ...
What's the delimiter in file 2? The pipe, "|" ? If so, taking the first line in file 2, isn't field 4 "ref"? And field 5 is "NC_000074.5"?

Regards and welcome to the forum,
Alister
...
4,518
Posted By curleb
cracks me up when folks in the UK say: "Duh!" ...
cracks me up when folks in the UK say: "Duh!"

Quick question for the OP...are the files sorted and the records are guaranteed in the same order? Otherwise, what's the key to tie the records? I...
4,518
Posted By alister
Assuming that the nth line in file1 corresponds...
Assuming that the nth line in file1 corresponds to the nth line in file2:
paste -d\\n file1 file2 |
awk '{
chr=$6; min=$7; max=$8; s=$11" "$12" "$13;
getline;
if (chr==$4 && $5>=min...
4,518
Posted By curleb
Alister, another quick and dirty masterpiece! ...
Alister, another quick and dirty masterpiece! Works great, for me...

But I must ask: what if they wanted to iterate over the lines in the file? Or would you just wrap it into a while read...?
...
Showing results 1 to 25 of 34

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