Search Results

Search: Posts Made By: patrick87
1,146
Posted By Lucas_0418
Hi Scrutinizer, Thanks Scurtinizer, thanks...
Hi Scrutinizer,
Thanks Scurtinizer, thanks for your advice.
\{1,\} is not nessesary, a [[:blank:]] is totally enough, the sed code is better after you edited it.
1,146
Posted By Scrutinizer
Awk approach with fixed strings: awk '$1=="b"...
Awk approach with fixed strings:
awk '$1=="b" && k=="a" {print p ORS $0}{p=$0; k=$1}' file


--
@lucas: nice sed. \{1,\} can be left out, no?


*edit* it could also be done like this.
sed...
1,146
Posted By Lucas_0418
Hi guy, Try this: sed -n...
Hi guy,
Try this:
sed -n '/^a[[:blank:]]\{1,\}/{N;/\nb[[:blank:]]\{1,\}/p;D}'

cheers.
2,643
Posted By Don Cragun
This is a fairly simple awk script. Here it is...
This is a fairly simple awk script. Here it is again with comments explaining what each line does:
awk '
$1 == f1 || NR == 1 { # If the 1st field is the same as the 1st field on the
...
2,643
Posted By Don Cragun
Yes, one of those lines is it. If you change: ...
Yes, one of those lines is it. If you change:
f0 = "" # Clear the saved line. (We do not want to print
# the current line twice if the 1st...
2,937
Posted By balajesuri
As per desired output.. with sum sorted in...
As per desired output.. with sum sorted in descending order.
perl -ane '$x{$F[0]}+=$F[1];$y{$F[0]}++; END{%x=reverse %x;print "$x{$_} $_ $y{$x{$_}}\n" for(reverse sort{$a<=>$b} keys %x)}' inputfile
2,937
Posted By Franklin52
Try this: awk '{a[$1]+=$2;b[$1]++}END{for(i in...
Try this:
awk '{a[$1]+=$2;b[$1]++}END{for(i in a)print i, a[i], b[i]}' file
2,665
Posted By rdcwayx
awk -F "" ' #...
awk -F "" ' # set Field Separator to null to split the letters.
NR==FNR{a[NR]=$0;next} # read the first file (file1) into array a , array index is line...
2,664
Posted By radoulov
Yes, I just wanted to show that you can post...
Yes,
I just wanted to show that you can post increment and check with a single expression :)
2,664
Posted By anurag.singh
I believe command in post #3 is doing the same. ...
I believe command in post #3 is doing the same.
@radoulov, a shorter/better command.
2,664
Posted By radoulov
Or even: awk '!_[$2]++' infileTo the OP:...
Or even:

awk '!_[$2]++' infileTo the OP: please elaborate more on how the output from anurag.singh's (https://www.unix.com/members/302086885.html) command is wrong.
2,664
Posted By anurag.singh
awk '{if(!a[$2]) print;a[$2]++;}' inPutfile
awk '{if(!a[$2]) print;a[$2]++;}' inPutfile
1,370
Posted By bartus11
Try: perl -pe 'BEGIN{open O, "reference_file_1";...
Try: perl -pe 'BEGIN{open O, "reference_file_1"; chomp(@a=<O>)} for $i (@a){$x="X" x length($i);s/$i/$x/g}' target_file > output_file
2,385
Posted By methyl
Firstly this seems remarkably close to one of...
Firstly this seems remarkably close to one of your many threads on this subject except that it has three files not two files....
2,861
Posted By durden_tyler
Franklin52's idea is much better. You do not...
Franklin52's idea is much better.
You do not really have to check if the first 3 or last 3 characters are non-X. The result is code brevity.


$
$ cat f25
>Read_1
XXXXXXXXXXABCXXXXXXS...
2,861
Posted By Franklin52
awk ' /^..X/{sub("^..X","XXX")} ...
awk '
/^..X/{sub("^..X","XXX")}
/X..$/{sub("X..$","XXX")}
1' file
2,861
Posted By durden_tyler
Not sure what you mean by "idea to archive it" -...
Not sure what you mean by "idea to archive it" - I don't see anything about archiving in your post. You probably mean "achieve it".

In any case, the script that follows takes care of the case...
1,714
Posted By ctsgnb
sed...
sed 's/X[^X]X/XXX/g;s/X[^X][^X]X/XXXX/g;s/X[^X][^X][^X]X/XXXXX/g' input >output
1,714
Posted By bartus11
perl -pe...
perl -pe 's/X[^X]X/XXX/g;s/X[^X]{2}X/XXXX/g;s/X[^X]{3}X/XXXXX/g;' input
3,166
Posted By rdcwayx
split the input data files to small files, and...
split the input data files to small files, and run the same awk command in different console.

then attach them again.

split input.data ABC

nohup awk -f command.awk referral.data ABCaa...
2,665
Posted By rdcwayx
awk -F "" ' NR==FNR{a[NR]=$0;next} !/>/ { ...
awk -F "" '
NR==FNR{a[NR]=$0;next}
!/>/ {
split(a[FNR],b,"");
{ for (i=1;i<=NF;i++) {printf ($i!=b[i])?b[i]:" "}
printf RS
}
}
' file1...
3,166
Posted By rdcwayx
awk ' NR==FNR {t=$0;gsub(/./,"x");a[t]=$0;next}...
awk '
NR==FNR {t=$0;gsub(/./,"x");a[t]=$0;next}
{
for (i in a) if ($0~i) sub(i,a[i])
}1
' referral.data input.data

>sample_1
SDFDSKLxxxxxxxxxxxxDSFAS

>sample_2...
2,665
Posted By rdcwayx
$ awk -F "" ' NR==FNR{a[NR]=$0;next} !/>/ { ...
$ awk -F "" '
NR==FNR{a[NR]=$0;next}
!/>/ {
split(a[FNR],b,"");
{ for (i=1;i<=NF;i++) {if ($i!=b[i]) printf b[i]}
printf RS
}
}
'...
2,604
Posted By Franklin52
Another approach: awk...
Another approach:
awk '{printf("%s%s\n",r,$1);r=ORS;$1=""} {
for (i=1;i<=length;i+=6) {
print substr($0,i,6)
}
}' RS= OFS= file
2,604
Posted By rdcwayx
awk '/>/||/^$/ {print;next} {printf $0}' infile...
awk '/>/||/^$/ {print;next} {printf $0}' infile |awk 'BEGIN{FS=OFS=""}! />/ {for (i=1;i<=int(NF/6);i++) $(i*6)=$(i*6) RS}1'
Showing results 1 to 25 of 27

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