Search Results

Search: Posts Made By: giuliangiuseppe
807
Posted By MadeInGermany
awk '($1>max[$3]) {max[$3]=$1; s[$3]=$0} END {for...
awk '($1>max[$3]) {max[$3]=$1; s[$3]=$0} END {for (i in s) print s[i]}' file---------- Post updated at 02:52 PM ---------- Previous update was at 02:42 PM ----------

R.Singh, your solution has all...
1,718
Posted By rovf
Wouldn't it much easier (from the viewpoint of...
Wouldn't it much easier (from the viewpoint of understandibility) to first transform the file into a format, where the third column is always zero, i.e. if you have a line

X Y 1

you would...
2,406
Posted By RudiC
Would this do (not too old bourne type shell...
Would this do (not too old bourne type shell required)?

ls f*.txt |
while read FN
do IFS="_." read X P1 O1 U1 L1 N1 P2 EX <<< $FN
NFN="${P1}_${O1}_${U1}_${L1}_${P2}.${EX}"
...
1,390
Posted By rdrtx1
awk ' {a[$1]=$1; f[$1]=NF; for (i=2; i<=NF;...
awk '
{a[$1]=$1; f[$1]=NF; for (i=2; i<=NF; i++) if ($i != "NA") b[$1 FS i]=$i} # load id and id columns arrays
END {
for (i in a) { #...
1,718
Posted By rdrtx1
try also: awk '!a[($3) ? $1 : $2, ($3) ? $2 :...
try also:
awk '!a[($3) ? $1 : $2, ($3) ? $2 : $1]++' infile
1,718
Posted By Don Cragun
You could also write that so it only evaluates...
You could also write that so it only evaluates field 3 once:
awk '!($3 ? A[$2,$1]++ : A[$1,$2]++)' infile
1,718
Posted By Aia
perl -lane '!$seen{$F[2]?"$F[1] $F[0] 0":$_}++...
perl -lane '!$seen{$F[2]?"$F[1] $F[0] 0":$_}++ and print' giuliangiuseppe.input
a b 0
a c 0
a f 1
b a 0
b c 1
d f 0
g h 1
1,718
Posted By RudiC
Although above solution works for the sample...
Although above solution works for the sample given, it will fail for others, e.g. the sequence of a b 0 and a b 1. Try this instead:
awk '
($2,$1,!$3) in B {next
}
...
1,348
Posted By RudiC
for file in path/to/file/example_number.ext ...
for file in path/to/file/example_number.ext
do TMP=${file%_number.ext}
something -input $file -output "new/path/${TMP}.new"
done
1,348
Posted By RudiC
You'll need an intermediate...
You'll need an intermediate step:FN=path/to/file/example_number.ext
TMP=${FN%_number.ext}
echo ${TMP##*/}
exampleto which you then can add the new path.
1,016
Posted By MadeInGermany
awk ' { k=$1 FS $2 } NR==FNR { a[k]=$3; next...
awk '
{ k=$1 FS $2 }
NR==FNR { a[k]=$3; next }
{ s[NR%n]=$3 }
(k in a) {
printf "%s %s",$1,$2
if (a[k]=="+") {
for (i=1; i<=n; i++) printf " %s",s[(NR+i)%n]
printf "\n"
} else...
1,108
Posted By RudiC
Far from clear. Assuming you mean that if second...
Far from clear. Assuming you mean that if second fields in file1 are 2 less than $2 in file2 then print, try:

awk '
FNR == NR {T[$1]=$2
next
}
NR <= L ...
1,121
Posted By Scrutinizer
Try something like: for file in folder/*_1.txt ...
Try something like:
for file in folder/*_1.txt
do
my_command "$file" "${file%_1.txt}_2.txt" > "${file%_1.txt}_executed.txt"
done &
wait

This should work with any reasonably POSIX...
1,050
Posted By RudiC
Try like awk '/^>/{FN=$0; sub (">", "",...
Try like awk '/^>/{FN=$0; sub (">", "", FN)}{print > FN}' file
Id1:
>Id1
textA
Id2:
>Id2
textB
1,050
Posted By RavinderSingh13
Hello Giuliano, Could you please try...
Hello Giuliano,

Could you please try following then, it may help you in same.

awk '/^>/{sub(/>/,X,$0);i=$0} {print >> i}' Input_file
Output will be as follows.

cat Id1
Id1
textA

cat...
1,618
Posted By RudiC
If you don't insist on the order of lines, tryawk...
If you don't insist on the order of lines, tryawk '!($1 in T) {T[$1]=$0; next} {T[$1]=""} END {for (t in T) if (T[t]) print T[t]}' file
f g h
k g h
x y z
1,618
Posted By Scrutinizer
Hi Giuliano, no the input file does not need to...
Hi Giuliano, no the input file does not need to be sorted.

The input file is read twice. The first time is when NR==FNR and in that section the number of occurrences of the label in field 1 gets...
1,618
Posted By Scrutinizer
This could be shortened to: awk...
This could be shortened to:

awk 'NR==FNR{A[$1]++; next} A[$1]==1' file file
1,618
Posted By RavinderSingh13
Hello giuliangiuseppe, Could you please try...
Hello giuliangiuseppe,

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

awk 'FNR==NR{A[$1]=$0;B[$1]++;next} {if(B[$1]==1){print $0}}' Input_file Input_file
Output will be as...
1,035
Posted By baris35
many thanks, Rudic! Boris
many thanks, Rudic!
Boris
1,035
Posted By RudiC
Try awk '!(2==gsub(/>0%/, "&"))'...
Try awk '!(2==gsub(/>0%/, "&"))' file
11,592
Posted By Don Cragun
Perhaps something more like: awk ' BEGIN...
Perhaps something more like:
awk '
BEGIN { printf(" ")
s = "sort"
}
FNR == 1 {
printf(" %s", files[++fc] = FILENAME)
}
{ d[$1, fc] = $2
c1[$1]
}
END { print ""
for(i in c1) {...
807
Posted By RavinderSingh13
Hello giuliangiuseppe, Could you please try...
Hello giuliangiuseppe,

Could you please try following solution, kindly don't use previous solution as I haven't tested that in different cases, following may help you. I have removed previous not...
1,507
Posted By Skrynesaver
If I understand you correctly you wish to...
If I understand you correctly you wish to maintain the row order of the file then split each record into an ID followed by any number of ref=>value tupples and sort the fields on increasing value......
1,507
Posted By RudiC
Somewhat clumsy compared to the perl oneliner...
Somewhat clumsy compared to the perl oneliner above... using awk however:awk 'function isort( A, B, n, i, j, holdA, holdB)
{for( i = 2 ; i <= n ; i++)
...
Showing results 1 to 25 of 44

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