sed prints out all data instead of substituted part which i want to extract [closed] - regex

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am aware, that this problem has been asked in slightly different ways many times before. But I couldn't adapt those solutions.
I am having a file header.out with the following content:
// some text before this
:type = "Primary Grid: Tau Format" ;
:deformation_timestep = 0. ;
:deformation_alpha = 0. ;
:deformation_dalpha = 0. ;
:deformation_h = 0. ;
:deformation_dh = 0. ;
:deformation_step = 0 ;
:adaptation_level = 0 ;
:connectivity_check = 1 ;
:volume_check = 1 ;
:point_check = 1 ;
:test_lib_check = 1 ;
:periodic_pairs_check = 1 ;
:is_balanced = 0 ;
:preserve_piles = 0 ;
:marker_1 = "WingMidTrailing" ;
:marker_2 = "WingMidLower" ;
:marker_3 = "WingMidUpper" ;
:marker_4 = "WingSide" ;
:marker_5 = "Farfield" ;
:marker_6 = "SymmetryPlane" ;
:marker_7 = "WingInnerLower" ;
:marker_8 = "WingInnerUpper" ;
:marker_9 = "WingInnerTrailing" ;
:marker_10 = "WingOuterLower" ;
:marker_11 = "WingOuterUpper" ;
:marker_12 = "WingOuterTrailing" ;
}
I need to extract the ID of the marker that belongs to the string "SymmetryPlane"
So in this case i want to have 6 as the output. All tries using sed and regular expressions failed.
What i have tried is:
sed 's/.*marker_\(.*\) = "SymmetryPlane.*/\1/' header.out
But this only gives me
:type = "Primary Grid: Tau Format" ;
:deformation_timestep = 0. ;
:deformation_alpha = 0. ;
:deformation_dalpha = 0. ;
:deformation_h = 0. ;
:deformation_dh = 0. ;
:deformation_step = 0 ;
:adaptation_level = 0 ;
:connectivity_check = 1 ;
:volume_check = 1 ;
:point_check = 1 ;
:test_lib_check = 1 ;
:periodic_pairs_check = 1 ;
:is_balanced = 0 ;
:preserve_piles = 0 ;
:marker_1 = "WingMidTrailing" ;
:marker_2 = "WingMidLower" ;
:marker_3 = "WingMidUpper" ;
:marker_4 = "WingSide" ;
:marker_5 = "Farfield" ;
6
:marker_7 = "WingInnerLower" ;
:marker_8 = "WingInnerUpper" ;
:marker_9 = "WingInnerTrailing" ;
:marker_10 = "WingOuterLower" ;
:marker_11 = "WingOuterUpper" ;
:marker_12 = "WingOuterTrailing" ;
}
I am not sure why this is happening.
Thanks in advance!

Just suppress the output (-n) and print after substitution (p):
sed -n 's/.*marker_\(.*\) = "SymmetryPlane.*/\1/p' header.out

Related

Decompressing a netCDF file

I have a comrpessed netCDF file called in.nc with a (_DeflateLevel=4). I want to decompress the file.
I've already tried using the following command but it doesn't change anything:
nccopy -d 0 in.nc out.nc
Here are the in.nc specifications:
time_counter = UNLIMITED ; // (12 currently)
y = 552 ;
x = 552 ;
variables:
float Q16c(time_counter, y, x) ;
Q16c:long_name = "Deep Sediment Particulate organic Matter" ;
Q16c:units = "mg C/m2" ;
Q16c:online_operation = "average" ;
Q16c:interval_operation = "900 s" ;
Q16c:interval_write = "1 month" ;
Q16c:cell_methods = "time: mean (interval: 900 s)" ;
Q16c:_FillValue = 1.e+20f ;
Q16c:missing_value = 1.e+20f ;
Q16c:coordinates = "time_centered nav_lat nav_lon" ;
Q16c:_Storage = "chunked" ;
Q16c:_ChunkSizes = 1, 552, 552 ;
Q16c:_DeflateLevel = 4 ;
Q16c:_Endianness = "little" ;

Running multiple arrays in SAS

I am trying to run 3 arrays in my SAS code and input each value into the variables in the last array, however, each time I run this code, it only populates the CREVASC_age column. Please let me know any thoughts on how to populate each age variable, in the third array, using the matching variables in the other arrays.
data Outc_adjust3; set Outc_adjust2;
ARRAY outcvars{3} CABG MI CREVASC;
ARRAY outcdys{3} CABGDY MIDY CREVASCDY;
ARRAY outc_age{3} CABG_age MI_age CREVASC_age;
Do I= 1 to 3;
if outcvars{3} = 1 then outc_age{3} = ageatenroll + (outcdys(3)/365.25);
else if outcvars{3} = 0 then do;
if EXTFLAG = 0 AND EXT2FLAG = 0 then outc_age{3} = AGE_WHIENDFU;
if EXTFLAG = 1 AND EXT2FLAG = 0 then outc_age{3} = AGE_EXT1ENDFU;
if EXT2FLAG = 1 AND EXT2MRC = 1 then outc_age{3} = age_endfu;
if EXT2FLAG = 1 AND EXT2SRC = 1 then outc_age{3} = age_ext1endfu;
end;
end;
run;
You hard coded {3} when you needed {I}. That is why only the third variable of the array was being dealt with.
Change the {3} to {I} for all the array indexed references inside the loop.

NCO: Copying data from one netcdf file into another only for a specific area

I have two NetCDF files with the exact same dimensions (time,lat,lon). Below is the header of one of the files.
netcdf file1 {
dimensions:
lon = 360 ;
lat = 177 ;
time = 360 ;
variables:
double lon(lon) ;
lon:units = "degrees_east" ;
lon:long_name = "Longitude" ;
double lat(lat) ;
lat:units = "degrees_north" ;
lat:long_name = "Latitude" ;
double time(time) ;
time:long_name = "Time" ;
time:units = "months since 1989-05-01 00:00" ;
double tmp(time, lat, lon) ;
tmp:_FillValue = -999000000. ;
}
I would like to copy values from one file into the other, but only for a small region determined by lat1,lat2 and lon1,lon2. Both files have the same time coordinates.
Something like: (lon1<lon<=lon2) & (lat1<lat<=lat2) file1 = file2
I was wondering if I could do that with NCO.
Any help will be appreciated. Thank
Read the manual section on the ncap2 where function. It describes how to use where on a hyperslab. That will do it:
*var_tmp=var2(:,0,:,:);
where (var1 < 0.5) var_tmp=1234;
var2(;,0,:,;)=var_tmp;

DO IF, ELSE: Else not being computed

Only the initial if statement variable computation is being completed--the ELSE part is being ignored. Can someone explain why? Many thanks.
DATASET ACTIVATE DataSet1.
DO IF ((A1_SCN2_PR1_UE = 0 & A1_SCN3_PR1_UE = 0 & A1_SCN4_PR1_UE = 0 & A1_SCN5_PR1_UE = 0) |
(A2_SCN2_PR1_UE = 0 & A2_SCN3_PR1_UE = 0 & A2_SCN4_PR1_UE = 0 & A2_SCN5_PR1_UE = 0) |
(A3_SCN2_PR1_UE = 0 & A3_SCN3_PR1_UE = 0 & A3_SCN4_PR1_UE = 0 & A3_SCN5_PR1_UE = 0)).
Compute FM_zero = 1.
ELSE.
Compute FM_zero = 0.
End IF.
EXECUTE.
Not sure why your ELSE is not being computed, but I suggest you drop the DO IF and go this way instead:
compute FM_zero =
((A1_SCN2_PR1_UE = 0 & A1_SCN3_PR1_UE = 0 & A1_SCN4_PR1_UE = 0 & A1_SCN5_PR1_UE = 0) |
(A2_SCN2_PR1_UE = 0 & A2_SCN3_PR1_UE = 0 & A2_SCN4_PR1_UE = 0 & A2_SCN5_PR1_UE = 0) |
(A3_SCN2_PR1_UE = 0 & A3_SCN3_PR1_UE = 0 & A3_SCN4_PR1_UE = 0 & A3_SCN5_PR1_UE = 0)).
This will put a 1 in all true cases and 0 in all false cases.
SPSS uses three-valued logic: True, False, or don't know (sysmis).
From the Syntax Reference Manual...
Missing values returned by the logical expression on DO IF or on any ELSE IF cause control to pass to
the END IF command at that point.
So generally you should put the sysmis test first in your DO IF and follow with appropriate ELSE IF/ELSE.

MProgressWindow does not refresh in Autodesk Maya API

I have an MProgressWindow class reference in Maya/C++. However the window stays at 0% (or even stays blank sometimes) and does not go up. What am I doing wrong?
MProgressWindow P ;
P.reserve() ;
P.setProgressMin( 0 ) ;
P.setProgressMax( 1000 ) ;
P.startProgress() ;
for (int i = 0; i < 1000; i++ ) {
// do some work
if ( i % 100 == 0) {
P.setProgressStatus( "Progress "+ MString() + i + "/" + MString() + P.progressMax() ) ;
P.advanceProgress( 100 ) ;
}
}
P.endProgress() ;
There is only one progress window in Maya, so you do not instantiate it yourself, it is already there vs one you will put in a dialog. That's why you do not see anything happening, you instantiate a memory object. Try this instead.
Side note - all methods are static so you call them by the base class name and ::
if ( !MProgressWindow::.reserve () )
return ;
MProgressWindow::setInterruptable (true) ;
MProgressWindow::setProgressRange (0, 1000) ;
P.setProgress (0) ;
P.startProgress () ;
for ( int i =0 ; i<1000 ; i++ ) {
if ( i != 0 && MProgressWindow::isCancelled () )
break ;
<do some work>
if ( i % 100 == 0 ) {
MProgressWindow::setProgressStatus ("Progress " + MString () + i + "/" + MString () + P.progressMax ()) ;
MProgressWindow::advanceProgress (100) ;
}
}
MProgressWindow::endProgress () ;