Search Results

Search: Posts Made By: jaysean
1,183
Posted By yazu
awk ' !a[$1" "$2" "$3] || $4 > a[$1" "$2" "$3]...
awk '
!a[$1" "$2" "$3] || $4 > a[$1" "$2" "$3] { a[$1" "$2" "$3] = $4 }
END { for (i in a) print i, a[i] }
' INPUTFILE
2,397
Posted By agama
Save the whole line, or the fields you want, when...
Save the whole line, or the fields you want, when you save the maximum.


awk -F'\t' '
{
if( $6 > a[$1"\t"$4"\t"$5] )
{
a[$1"\t"$4"\t"$5] = $6
output[$1"\t"$4"\t"$5] = $0;...
15,041
Posted By rdcwayx
awk -F "\t" '{a[$1 FS $2 FS $3]=(a[$1 FS $2 FS...
awk -F "\t" '{a[$1 FS $2 FS $3]=(a[$1 FS $2 FS $3]>$NF)?a[$1 FS $2 FS $3]:$NF}
END {for (i in a) print i FS a[i]}' urfile
15,041
Posted By frans
bash #!/bin/bash IFS=" " # is a Tab sort -r...
bash
#!/bin/bash
IFS=" " # is a Tab
sort -r infile | while read A B C D
do [ "$L" != "$A$B$C" ] && { L=$A$B$C; echo -e "$A\t$B\t$C\t$D"; }
done

if you need a sorted output
#!/bin/bash...
15,041
Posted By Christoph Spohr
Hi, try: awk '{if ($4 > a[$1" "$2"...
Hi,

try:

awk '{if ($4 > a[$1" "$2" "$3])a[$1" "$2" "$3]=$4}END{for (i in a) print i, a[i]}' file

Output:

3333 4444 BBBB 0.7
1111 2222 AAAA 0.9


HTH Chris
2,127
Posted By rdcwayx
awk '{a[$0]++}END{for (i in a) print i, a[i]}'...
awk '{a[$0]++}END{for (i in a) print i, a[i]}' urfile
3,074
Posted By pseudocoder
find . -type f -name "*.doc" | while read fn; do ...
find . -type f -name "*.doc" | while read fn; do
mv -v "$fn" "$(echo $fn | sed 's/\.doc$/\.txt/')"
done
1,964
Posted By Franklin52
Another way is to read the file twice: awk...
Another way is to read the file twice:
awk 'NR==FNR{a[$1]++;next} a[$1]>=min' min=3 file file
1,964
Posted By radoulov
awk 'END { for (i = 0; ++i <= NR;) if...
awk 'END {
for (i = 0; ++i <= NR;)
if (count[pos[i]] >= min)
print pos[i]
}
{
pos[NR] = $0; count[$0]++
}' min=3 infile

If your awk implementation has no access to NR...
1,964
Posted By bartus11
awk '{a[$0]++}END{for (i in a) if (a[i]>=3) for...
awk '{a[$0]++}END{for (i in a) if (a[i]>=3) for (j=1;j<=a[i];j++) print i}' file
3,716
Posted By bartus11
Fix for Guru's code: awk 'NR==FNR{a[$1"...
Fix for Guru's code: awk 'NR==FNR{a[$1" "$2]=$3;next;}length(a[$1" "$2])>0{ if (a[$1" "$2] > $3) print $1, $2,a[$1" "$2]; else print;}' file1 file2
3,716
Posted By guruprasadpr
Oops... awk 'NR==FNR{a[$1"...
Oops...


awk 'NR==FNR{a[$1" "$2]=$3;next;}($1" "$2 in a){if(a[$1" "$2] > $3) print $1, $2,a[$1" "$2]; else print;}' file1 file2


Guru.
2,809
Posted By guruprasadpr
Hi awk '{a[$1]++; j++}END{ for (i in a)...
Hi

awk '{a[$1]++; j++}END{ for (i in a) print a[i],i,j;}' infile

Guru.
15,291
Posted By Scott
As an example: ls A | while read FILE; do...
As an example:


ls A | while read FILE; do
cat A/"$FILE" B/"$FILE" >> C/"$FILE"
done

to append the A and B files to new files (with the same names) somewhere else.
15,291
Posted By Scott
One way, assuming A and B directories are in the...
One way, assuming A and B directories are in the current directory, and that A and B contain only files:


ls A | sed "s|.*|cat A/& >> B/&|" | sh



$ ls A
1.txt 2.txt 3.txt

$ cat A/1.txt...
Showing results 1 to 15 of 15

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