我在一个文件中有两列,我想自动对每行的两个值求和
例如
read write
5 6
read write
10 2
read write
23 44
Run Code Online (Sandbox Code Playgroud)
我想总结每行的"读"和"写".总结之后,我找到最大总和并将该最大值放在一个文件中.我觉得我必须使用grep -v来消除每行的列标题,这就像答案中所说的那样,使得代码效率低下,因为我只是为了读取一行而贪图整个文件.
我目前在一个bash脚本中(在一个for循环中,其中$ x是文件名)将这些列逐行求和
lines=`grep -v READ $x|wc -l | awk '{print $1}'`
line_num=1
arr_num=0
while [ $line_num -le $lines ]
do
arr[$arr_num]=`grep -v READ $x | sed $line_num'q;d' | awk '{print $2 + $3}'`
echo $line_num
line_num=$[$line_num+1]
arr_num=$[$arr_num+1]
done
Run Code Online (Sandbox Code Playgroud)
但是,要汇总的文件有270,000多行.该脚本现在已经运行了几个小时,而且还没有完成.有没有更有效的方式来写这个,所以它不需要这么长时间?
我有一个这样的清单
一个人
Cperson
APerson2
BPerson
我希望它如此出现
一个
Aperson Aperson2
乙
Bperson
C
Cperson
我在这里发现了一篇解释它的帖子:http: //pmosd.blogspot.com/2013/07/headers-in-angularjs-ng-repeats.html
但作为一个Angular noob,我不知道在js文件中放置函数和过滤器的位置以及如何将其正确编码到我的html中.我试着关注我链接的帖子,但是我的无序列表中的联系人名称不会显示在浏览器中.这是我目前的JS和HTML文件.我曾尝试将过滤器和功能放在不同的地方,但这是我最近的尝试.
Directory.js:
'use strict';
var myApp = angular.module('myappname');
myApp.controller('DirectoryCtrl', function ($scope) {
$scope.contacts = [{
'fname': 'Randy',
'lname': 'Johnson',
'location': 'Seattle, WA'
}, {
'fname': 'Andy',
'lname': 'Pettite',
'location': 'Bronx, NY'
}, {
'fname': 'Jon',
'lname': 'Lester',
'location': 'Boston, MA'
}];
});
myApp.filter("headerChunk", function () {
return function (orig, same, getChunkID) {
if (!(orig instanceof Array)) return orig;
if (orig.length == 0) …
Run Code Online (Sandbox Code Playgroud) javascript contact-list angularjs angularjs-ng-repeat angularjs-filter