我有一个包含少量列的数据集,但是当列1具有偶数时,我想将其分隔为新文件。第1列格式为Var1 Var2 Var3
M1 * 2 3
M3 * 4 2
M2 * 1 5
M6 * 1 6
,此处为奇数(1)。
数据集:
/**
* This pans the map when the user is moused down and at the end of the map
* bounding box.
*
* @return {undefined}
*/
DrawingManager.prototype._mapPanHandler = function (googleMapEvent) {
var self = this;
var event = googleMapEvent;
var overlay = new google.maps.OverlayView();
overlay.draw = function() {};
overlay.setMap(map);
var projection = overlay.getProjection();
var pixelpoint = projection.fromLatLngToDivPixel(map.getCenter());
var proj = overlay.getProjection();
var thepix = proj.fromLatLngToDivPixel(event.latLng);
var nE = map.getBounds().getNorthEast();
var sW = map.getBounds().getSouthWest();
var nE = proj.fromLatLngToDivPixel(nE);
var sW = proj.fromLatLngToDivPixel(sW);
var north = nE.y;
var east = nE.x;
var south = sW.y;
var west = sW.x;
var appx_north, appx_east, appx_south, appx_west;
if (Math.round(thepix.y) <= Math.round(north + 50)) {appx_north = true;}
if (Math.round(thepix.x) >= Math.round(east - 50)) {appx_east = true;}
if (Math.round(thepix.y) >= Math.round(south - 50)) {appx_south = true;}
if (Math.round(thepix.x) <= Math.round(west + 50)) {appx_west = true;}
clearInterval(self._panTimer);
if (!appx_north && !appx_east && !appx_south && !appx_west) {
return;
}
var panMap = function () {
var movementAmount = 3;
if (appx_north) { pixelpoint.y -= movementAmount; }
if (appx_east) { pixelpoint.x += movementAmount; }
if (appx_south) { pixelpoint.y += movementAmount; }
if (appx_west) { pixelpoint.x -= movementAmount; }
point = projection.fromDivPixelToLatLng(pixelpoint);
map.setCenter(point);
}
panMap();
self._panTimer = setInterval(panMap, 10);
};
答案 0 :(得分:1)
试试这个:
$ awk '!(substr($1,2)%2)' infile > new_file
$ cat new_file
Var1 Var2 Var3
M2 * 1 5
M6 * 1 6
答案 1 :(得分:0)
使用grep:
class Data{
public:
int a;
Data(int A): a(A) {}
operator int() {return a;}
};
int operator=(int &lhs, Data* rhs){
lhs = rhs->a;
return lhs;
}
int main(){
Data d(10);
int A = &d;
return 0;
}
这将获得第一个空格前的字符均匀的所有行,即第一列以偶数结束。
答案 2 :(得分:0)
awk
救援!
$ awk '$1~/[02468]$/' file
M2 * 1 5
M6 * 1 6
检查第一个字段的最后一个数字是否是其中一个。
添加标题
$ awk 'NR==1 || $1~/[02468]$/' file
Var1 Var2 Var3
M2 * 1 5
M6 * 1 6