Search Results

Search: Posts Made By: cosmologist
1,629
Posted By Scrutinizer
You need arrays for that. Try this: awk '{for...
You need arrays for that. Try this:
awk '{for (i=1; i<=NF; i++) if ( $i > M[i] ) M[i]=$i} END{ for (i=1; i<=NF; i++) printf "%s ",M[i]; print}' infile
1,252
Posted By 47shailesh
assuming your column is 1 use following awk...
assuming your column is 1 use following

awk '{x+=$1} END {print x}' infile
1,252
Posted By jlliagre
47shailesh's script can easily be enhanced to...
47shailesh's script can easily be enhanced to achieve that:
awk '{x+=$1;print x} END {print x}' infile
908
Posted By fpmurphy
You can also do it using bash or ksh for...
You can also do it using bash or ksh

for ((i=2; i<7; i++)); do
for ((j=30; j<37; j++)); do
printf "((\$$j)-(\$$i)^2\n" j i
done
done
6,403
Posted By Corona688
It does? That's a bug. Muttermuttergrumble. ...
It does? That's a bug. Muttermuttergrumble. Working on it.

---------- Post updated at 10:19 PM ---------- Previous update was at 10:17 PM ----------

What a difference one letter makes...
...
6,403
Posted By Corona688
If you meant 4+8+5, then sure. I'll let it work...
If you meant 4+8+5, then sure. I'll let it work on multiple columns, too.

$ cat data
1 5
5 6
2 7
6 8
3 9
7 10
4 11
8 12
5 13
9 ...
6,403
Posted By Corona688
Surely there's a way to do that with awk. awk...
Surely there's a way to do that with awk. awk doesn't have a single function for it of course, since it doesn't make much sense to do a boxcar average on a single line...

Let me see if I have the...
908
Posted By agama
Something like this; can be done in any scripting...
Something like this; can be done in any scripting language fairly easily


awk '
BEGIN {
for( i =2; i < 7; i++ )
for( j = 30; j < 37; j++ )
printf(...
2,084
Posted By vgersh99
nawk -v row=4 -f cosmo.awk myFile cosmo.awk: ...
nawk -v row=4 -f cosmo.awk myFile
cosmo.awk:

NR==1 {ARGV[ARGC++] = ARGV[1]}
FNR==NR {if (row==FNR) split($0, rowA);next}
{
for(i=1;i<=NF;i++)
printf("%d%c", (i==1)?$i:$i/rowA[i],...
2,084
Posted By itkamaraj
bash-3.00$ cat test 8 10 12 14 16 18 0 2...
bash-3.00$ cat test
8 10 12 14 16 18 0 2 6
2 4 6 8 10 12 16 18 10
6 8 12 16 18 0 2 2 6
2 2 2 2 2 2 2 2 2
10 12 16 4 8 16 4 16 0
8 10 14 16...
10,919
Posted By bartus11
Then try this:#!/usr/bin/perl open...
Then try this:#!/usr/bin/perl
open I,"$ARGV[0]";
chomp(@x=<I>);
for ($i=0;$i<=$#x;$i++){
@y=split / +/,$x[$i];
for ($j=0;$j<=$#y;$j++){
push @{$c[$j]},$y[$j];
}
}
for...
4,101
Posted By bartus11
Sorry, I didn't see your update. Try this: perl...
Sorry, I didn't see your update. Try this: perl -0pe '$f=`cat file1`;$f=~s/\n//;s/\nexit.?$/ $f$&/' file2
4,101
Posted By bartus11
You are subtracting from the wrong variable. Try...
You are subtracting from the wrong variable. Try this: awk 'NR==FNR{x=$0-1;next}/awk/&&/Delete_zero_flux/{$4=$4x}1' test test2
4,101
Posted By bartus11
Assuming that words "awk" and "Delete_zero_flux"...
Assuming that words "awk" and "Delete_zero_flux" appear together only on the line that you want to change:awk 'NR==FNR{x=$0;next}/awk/&&/Delete_zero_flux/{$4=$4x}1' file2 file1
852
Posted By Corona688
When you execute something, it runs it in a...
When you execute something, it runs it in a separate shell, which has its own current directory. So changing it's directory doesn't change yours.

You have to run the script in your own shell,...
1,014
Posted By ctsgnb
$ awk '!$2&&!c++' tst 9630. 0 $ awk...
$ awk '!$2&&!c++' tst
9630. 0
$ awk '!$2&&!c++{print NR}' tst
15
1,014
Posted By michaelrozar17
This one...? sed '/ 0$/!d;q' inputfile
This one...?
sed '/ 0$/!d;q' inputfile
1,612
Posted By bartus11
#!/usr/bin/perl open I, "$ARGV[0]"; while...
#!/usr/bin/perl
open I, "$ARGV[0]";
while (<I>){
$n++;
chomp;
@F=split / /;
for ($i=0;$i<=$#F;$i++){
push @{$c[$i]},$F[$i];
}
}
for ($i=1;$i<=$#F;$i++){
$min[$i]=$c[$i][0];...
3,321
Posted By Peasant
Check printf and %f. Here a simple shell...
Check printf and %f.

Here a simple shell loop and awk code to accomplish the same :
file[1-4] matches file1 to file4.

for i in file[1-4]; do awk ' { sum1+=$1;sum2+=$2;sum3+=$3} END { printf...
3,321
Posted By agama
This will handle multiple files and multiple...
This will handle multiple files and multiple columns. Each file can have a different number of columns.


#!/usr/bin/env ksh
awk '
function show_totals( i )
{
for( i =...
2,895
Posted By Franklin52
Try: awk '{print "hi \047 " $1}' all >...
Try:
awk '{print "hi \047 " $1}' all > testing.txt

You can also use a variable for the quote like:
awk -v q="'" '{print "Hi " q " " $1}' all > testing.txt
2,895
Posted By bartus11
awk "{print \"x ' y\"}" all
awk "{print \"x ' y\"}" all
2,108
Posted By bartus11
Try this in that directory:for i in *; do perl -i...
Try this in that directory:for i in *; do perl -i -ne 'print if $.!=69' $i; done
2,108
Posted By bartus11
You can join them like this: paste -d" " file1...
You can join them like this: paste -d" " file1 file2 file3
10,919
Posted By bartus11
#!/usr/bin/perl open I,"$ARGV[0]"; ...
#!/usr/bin/perl
open I,"$ARGV[0]";
chomp(@x=<I>);
for ($i=0;$i<=$#x;$i++){
@y=split / +/,$x[$i];
for ($j=0;$j<=$#y;$j++){
push @{$c[$j]},$y[$j];
}
}
for ($i=0;$i<=$#y;$i++){
for...
Showing results 1 to 25 of 34

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