1

嗨,我正在尝试从 .dat 文件中 grep 某些行并将它们放入新文件 test.dat(或 .txt)中。我想 grep 日期/时间 (2012Sep212357) 和以 (FD12P 开头并以 PARS 结尾的行。请记住,2012Sep 之后的日期/时间正在改变。我试过了

grep '^2012Sep.*AA$' |'^FD12P.*PARS$' file.dat > test.dat 

但它不起作用,输出应该是:

2012Sep212357,FD12P_S/N ,      OK  ,  FD, 102, 26578, 16081, C,   0,   0,   0,     0.00,    41.18,    0.0,  0.000,  0.000,  0.000,  0.000,  0.000,  0.000, 15.20,      4, BEL_RAIN,      OK  ,  0.00, -0.20, -1.40, -1.80, -1.40, -1.40, -1.40, 311.0, ,          ,      0,0.0000000,0.0000000, Snow11_Icing ,   OK  , 33, 0909, 190, 17.03, 11111, FD, WS425_SN_,      OK  , 208, 210, 5, 5,  11.4,  11.4,  11.7,   5.9,   6.0,   4.9, 196.3,   6.4, 172.0,   3.5, 194.0,   6.4, 172.0,   1.8, 178.0,   4.6,   6.0,  0,   0.0,   1.6, CR3000_SN_,      OK  , "2012-09-21 20:01:30", "SN_1838", 12.90, 16.47, 17.06, 50.22,1001.1,  0.00,  0.00,2419.6, 432.1,   -4.6,   3.1, 188.5, S78D_SN_,      OK  ,64403.0,64841.0,  10.0, 211.5,   5.4, 206.5,   4.3,   5.4, 209.8,   3.2, 190.3,   5.4, 214.3,   1.6, 191.1,   3.8,  23.2,  0,   0.0,   1.1,

原始文件的样本(我在文件中有很多类似下面的行):

2012Sep212357 23:56:03.06250, AAA_YMDHMS, 2012, 9, 21, 23, 56, 4, POSS_71,      OK  ,  15.0,   73.2,   0.0,   0.0,   C,   0.0,   0.3,   0.6,PS711 78:218:17:41 189.9 205.5  112        1.7        7.3 60  15  51  73.2   0.0     2080,PS712,PS713,PS714,PS715,PS716 F# 51 2.03 7.39 54.98 2.06 0.89 681.1  0.3 11.0 112  14.6 C    376 0.00 0.00 0  0  2  1  112  1.7 189.8 205.4 157.1 192.0 78.5 32.0 928.0 2.0 0.0 -99.0 0.0 10.7 10.7 10000000.0 376 T 4 I 0 ,dia  2 6, 28 22 4,dia  3 5, 26 34 4,dia  4 3 18 17, 3,dia  5 4 25 13 4 1,,dia  6 5 12 7 1,dia  7 6 10 6,dia  8 5 12 4,dia  9 1 3 1,dia  10 2 3 1,dia  11 2 4,dia  12 0 0 1,dia  13 1 1,dia  14 1,dia  15 1 1,dia  16 1 1 1,dia  17 1,dia  18 1 3,dia  22 0 1,dia  23 1,dia  24 1 1,dia  25 1,dia  26 1,dia  29 1,dia  30 1,dia  31 2 2,dia  32 0 3,dia  33 1 2,dia  34 0 1 1,dia  35 1,dia  36 0 3,dia  37 0 2,dia  38 1 2,dia  39 1 2,dia  40 0 2,dia  41 2,dia  42 1 4 1,dia  43 2,dia  44 1 2,dia  45 1 2,dia  47 0 3,dia  49 2,dia  52 2,dia  59 1,dia  60 1,dia  61 1,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia , YANKEE_S/N_0706011,      OK  ,  46.9,  48.2,  -1.3,  17.0,   2.5, 1.000,  -0.8,   0.0,  -0.1,  -0.1,  -1.5,  -3.5,   0.0,   0.0,   0.0,   0.0, CT25K_S/N_A42101,      OK  ,CT0,20,2,3,00, /////, /////, /////,00000300,100,N,100,25,82,206,-4,7,LF7HN1,6,-2,6,5,5,4,4,4,3,4,3,2,2,3,3,2,2,2,3,2,2,2,3,3,2,2,3,3,3,3,3,3,3,3,4,4,4,3,4,4,5,3,4,5,4,3,5,3,6,4,1,5,3,3,4,5,3,3,0,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, FD12P_S/N ,      OK  ,  FD, 102, 26578, 16081, C,   0,   0,   0,     0.00,    41.18,    0.0,  0.000,  0.000,  0.000,  0.000,  0.000,  0.000, 15.20,      4, BEL_RAIN,      OK  ,  0.00, -0.20, -1.40, -1.80, -1.40, -1.40, -1.40, 311.0, ,          ,      0,0.0000000,0.0000000, Snow11_Icing ,   OK  , 33, 0909, 190, 17.03, 11111, FD, WS425_SN_,      OK  , 208, 210, 5, 5,  11.4,  11.4,  11.7,   5.9,   6.0,   4.9, 196.3,   6.4, 172.0,   3.5, 194.0,   6.4, 172.0,   1.8, 178.0,   4.6,   6.0,  0,   0.0,   1.6, CR3000_SN_,      OK  , "2012-09-21 20:01:30", "SN_1838", 12.90, 16.47, 17.06, 50.22,1001.1,  0.00,  0.00,2419.6, 432.1,   -4.6,   3.1, 188.5, S78D_SN_,      OK  ,64403.0,64841.0,  10.0, 211.5,   5.4, 206.5,   4.3,   5.4, 209.8,   3.2, 190.3,   5.4, 214.3,   1.6, 191.1,   3.8,  23.2,  0,   0.0,   1.1, PARS_SN ,      OK  ,  0.00, 147.7,    C,   -10.0,   9999,  19.0, 10057,     0,   0.0,   0.0,   0.0,   0.0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TB_SN_ ,      OK  ,   0.0,   0.0,   0.0,   0.0, GEONOR_SN_,      OK  ,   1.1,  -0.1,   0.0,  -0.5, MP3000_SN_3031,      OK  , 13611, 09/21/12 23:52:03,   201, 290.8410,  54.5700, 992.6000, 224.9700,   0.0000, 13616, 09/21/12 23:52:52,   301,   2.006,   0.000,  -1.000, 13629, 09/21/12 23:53:40,   301,   2.153,   0.000,  -1.000, 13612, 09/21/12 23:52:49,   401, Zenith33, 290.841, 290.619, 290.324, 289.965, 289.594, 289.315, 289.019, 288.657, 288.252, 287.874, 287.473, 286.550, 285.484, 284.489, 283.557, 282.448, 281.549, 280.729, 279.510, 278.444, 277.386, 276.560, 275.714, 275.025, 274.243, 273.660, 272.269, 270.575, 269.615, 268.371, 267.229, 265.628, 264.201, 262.967, 261.651, 259.787, 258.405, 256.936, 255.301, 253.573, 251.715, 249.948, 248.309, 246.431, 244.513, 242.739, 240.876, 238.979, 237.113, 235.236, 233.310, 231.360, 229.586, 227.806, 226.248, 224.444, 222.997, 221.686, 13613, 09/21/12 23:52:50,   402, Zenith33,   8.112,   7.620,   7.356,   7.167,   7.001,   6.926,   6.905,   6.821,   6.749,   6.753,   6.634,   6.261,   5.949,   5.797,   5.612,   5.539,   5.345,   5.309,   5.308,   5.128,   4.854,   4.559,   4.412,   4.302,   4.119,   3.899,   3.280,   2.939,   2.634,   2.426,   2.251,   2.077,   1.768,   1.456,   1.191,   1.016,   0.836,   0.688,   0.572,   0.498,   0.420,   0.342,   0.315,   0.268,   0.247,   0.216,   0.169,   0.151,   0.117,   0.086,   0.079,   0.057,   0.043,   0.034,   0.027,   0.029,   0.025,   0.023, 13614, 09/21/12 23:52:50,   403, Zenith33,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.001,   0.002,   0.003,   0.004,   0.004,   0.005,   0.006,   0.006,   0.006,   0.005,   0.005,   0.006,   0.006,   0.006,   0.005,   0.004,   0.005,   0.007,   0.001,   0.001,   0.001,   0.001,   0.001,   0.001,   0.000,   0.001,   0.003,   0.001,   0.001,   0.002,   0.004,   0.001,   0.001,   0.004,   0.002,   0.002,   0.001,   0.000,   0.002,   0.000,   0.000,   0.002,   0.001, 13615, 09/21/12 23:52:51,   404, Zenith33,  56.270,  53.729,  53.026,  52.810,  52.940,  53.694,  54.346,  54.964,  55.335,  56.838,  57.384,  58.904,  60.251,  62.294,  63.354,  65.906,  66.386,  69.111,  73.093,  75.221,  75.959,  76.108,  77.720,  79.306,  80.117,  79.051,  73.398,  70.405,  73.031,  72.626,  69.891,  68.496,  69.016,  64.496,  60.284,  56.164,  50.403,  46.814,  43.598,  40.230,  38.220,  36.595,  37.270,  35.931,  35.872,  34.573,  34.382,  31.848,  30.184,  28.592,  27.367,  26.572,  25.385,  24.167,  22.947,  22.196,  20.102,  17.273, 13617, 09/21/12 23:53:37,   401, Angle Scan32(N), 290.841, 290.341, 290.135, 289.888, 289.601, 289.359, 289.063, 288.816, 288.596, 288.292, 287.907, 286.989, 286.151, 285.159, 283.948, 282.604, 281.604, 280.663, 279.693, 278.789, 278.079, 277.346, 276.519, 275.626, 274.793, 274.033, 272.555, 271.680, 270.758, 269.641, 268.433, 266.921, 265.443, 264.229, 263.036, 261.562, 260.179, 258.611, 257.035, 255.240, 253.437, 251.850, 250.007, 248.111, 246.297, 244.386, 242.365, 240.776, 239.021, 237.268, 235.613, 233.999, 232.464, 230.806, 229.090, 227.562, 226.043, 224.730, 13620, 09/21/12 23:53:38,   Angle Scan32(S),   7.814,   6.994,   6.357,   5.945,   5.634,   5.442,   5.438,   5.371,   5.350,   5.230,   5.403,   4.970,   4.875,   4.949,   5.079,   5.089,   4.678,   4.723,   4.734,   4.826,   4.625,   4.731,   5.251,   5.544,   5.911,   6.282,   7.083,   7.490,   7.369,   6.637,   5.359,   3.880,   2.902,   1.757,   1.279,   1.035,   0.725,   0.560,   0.455,   0.361,   0.275,   0.255,   0.190,   0.162,   0.130,   0.122,   0.103,   0.103,   0.080,   0.080,   0.062,   0.061,   0.056,   0.033,   0.026,   0.032,   0.025,   0.020, 13624, 09/21/12 23:53:39,   403, Angle Scan32(S),   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.003,   0.002,   0.003,   0.003,   0.004,   0.006,   0.006,   0.005,   0.005,   0.007,   0.006,   0.003,   0.003,   0.002,   0.004,   0.003,   0.001,   0.001,   0.001,   0.000,   0.001,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.000,   0.001,   0.002,   0.003,   0.000, 13627, 09/21/12 23:53:40,   404, Angle Scan32(S),  56.426,  52.621,  49.854,  47.596,  47.538,  48.077,  50.507,  49.331,  49.623,  49.122,  51.626,  50.226,  51.898,  55.446,  57.410,  61.732,  58.361,  60.002,  61.793,  65.138,  68.036,  74.196,  82.373,  85.787, 100.000, 100.000, 100.000, 100.000, 100.000, 100.000, 100.000, 100.000, 100.000,  85.190,  66.155,  53.728,  37.351,  23.545,  17.741,  14.367,  12.172,  13.330,  10.572,  10.516,   9.346,   8.075,   6.828,   5.445,   5.651,   5.252,   5.502,   6.274,   6.017,   6.092,   6.767,   6.991,   5.608,   4.837, 13619, 09/21/12 23:53:37,   401, Angle Scan32(A), 290.841, 290.480, 290.186, 289.854, 289.535, 289.214, 288.917, 288.581, 288.361, 288.152, 287.764, 286.828, 286.006, 284.883, 283.694, 282.416, 281.453, 280.518, 279.586, 278.614, 277.817, 277.085, 276.148, 275.167, 274.327, 273.550, 271.972, 270.837, 269.920, 268.786, 267.391, 265.698, 264.125, 263.022, 261.916, 260.413, 259.030, 257.379, 255.820, 253.810, 251.899, 250.295, 248.273, 246.140, 244.078, 242.025, 239.986, 238.294, 236.323, 234.485, 232.698, 230.971, 229.531, 227.863, 226.234, 224.886, 223.635, 222.540, 13622, 09/21/12 23:53:38,   402, Angle Scan32(A),   7.987,   7.424,   6.955,   6.634,   6.380,   6.247,   6.209,   6.208,   6.193,   6.097,   6.195,   5.877,   5.729,   5.754,   5.761,   5.682,   5.312,   5.292,   5.284,   5.308,   5.132,   5.058,   5.182,   5.206,   5.294,   5.250,   5.203,   4.958,   4.590,   4.145,   3.543,   2.837,   2.317,   1.620,   1.235,   1.011,   0.768,   0.615,   0.497,   0.416,   0.336,   0.293,   0.233,   0.196,   0.162,   0.141,   0.123,   0.115,   0.092,   0.091,   0.069,   0.064,   0.054,   0.033,   0.026,   0.032,   0.026,   0.021, 13625, 09/21/12 23:53:39,   403, Angle Scan32(A),   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.000,   0.000,   0.002,   0.003,   0.003,   0.003,   0.004,   0.005,   0.007,   0.006,   0.005,   0.005,   0.008,   0.006,   0.003,   0.003,   0.002,   0.004,   0.003,   0.001,   0.001,   0.001,   0.000,   0.001,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.000,   0.001,   0.002,   0.003,   0.000, 13628, 09/21/12 23:53:40,   404, Angle Scan32(A),  56.682,  53.972,  51.892,  50.578,  50.563,  50.727,  52.154,  52.163,  52.709,  52.844,  54.714,  54.856,  56.689,  60.229,  62.028,  64.870,  63.262,  65.752,  68.310,  71.277,  73.323,  76.555,  79.852,  81.290,  88.961,  92.860, 100.000, 100.000, 100.000, 100.000, 100.000,  99.377,  92.961,  72.472,  62.030,  54.508,  43.265,  32.818,  27.337,  23.694,  21.524,  22.368,  19.811,  19.031,  18.017,  16.873,  15.321,  13.403,  13.020,  12.580,  12.825,  13.851,  13.301,  13.059,  13.511,  13.757,  11.592,  10.430, 290.841,  54.570, 992.600, 224.970,   0.000, BACIC_, No ,belraw3110.0,belsum  -1.8,fdsum   0.0,fdsnow   0.0,yksum  -3.5,ykcsum   0.0,S78D-  OK  ,PARtotal 147.7,ParCnt   0.0,Counter 594.0,Max_ws   6.4,Dir 172.0,Delta_ws   4.6,gust   0.0
2012Sep212358 23:57:03.06250, AAA_YMDHMS, 2012, 9, 21, 23, 57, 4, POSS_71,      OK  ,  15.0,   73.2,   0.0,   0.0,   C,   0.0,   0.3,   0.6,PS711 78:218:17:42 390.3 297.2   64         .1        2.1 60  15  49  73.2   0.0     2080,PS712,PS713,PS714,PS715,PS716 F# 49 2.03 2.14 1.03 2.01 1.07 19.2  0.2 12.4 64  14.7 C    376 0.00 0.00 0  0  3  1  64  0.1 390.3 297.2 149.0 176.3 83.8 32.0 944.0 2.3 0.0 -99.0 0.0 10.7 10.7 10000000.0 376 T 1 I 0 ,dia  2 5, 26 20 3,dia  3 4, 26 20 3,dia  4 6 22 18, 1 0 0 1 0 1,dia  5 4 15 20 3 0, 1,dia  6 4 15 8 4,dia  7 8 14 7,dia  8 4 7 6 0 0 1,dia  9 4 9 4,dia  10 3 7,dia  11 3 1 1,dia  12 1 3,dia  14 2 2,dia  15 1 3,dia  16 1 2 1,dia  17 4 2,dia  21 1,dia  22 0 1,dia  23 2 1,dia  25 0 1,dia  26 1,dia  27 1,dia  29 1,dia  30 1 1,dia  31 1,dia  32 2,dia  33 1 1,dia  34 0 2,dia  36 0 1,dia  37 1 2,dia  38 1 1,dia  39 0 2,dia  40 0 0 1,dia  41 3 3 1,dia  42 1,dia  43 2 0 1,dia  45 1 1,dia  47 0 1,dia  48 1 1,dia  55 1,dia  59 1,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia ,dia , YANKEE_S/N_0706011,      OK  ,  55.7,  56.8,  -1.2,  17.0,   3.2, 1.000,  -0.9,   0.0,   0.0,  -0.1,  -1.5,  -3.5,   0.0,   0.0,   0.0,   0.0, CT25K_S/N_A42101,      OK  ,CT0,20,2,3,00, /////, /////, /////,00000300,100,N,100,25,82,206,-4,7,LF7HN1,6,-2,6,5,5,4,4,4,3,4,3,2,2,3,3,2,2,2,3,2,2,2,2,3,2,2,3,3,3,3,3,3,3,3,4,4,4,3,4,5,6,2,5,4,5,3,3,4,5,4,2,4,3,2,4,5,3,4,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, FD12P_S/N ,      OK  ,  FD, 102, 20517, 16565, C,   0,   0,   0,     0.00,    41.18,    0.0,  0.000,  0.000,  0.000,  0.000,  0.000,  0.000, 15.20,      4, BEL_RAIN,      OK  ,  0.00, -0.20, -1.40, -1.80, -1.40, -1.40, -1.40, 311.0, ,          ,      0,0.0000000,0.0000000, Snow11_Icing ,   OK  , 33, 0909, 182, 17.07, 11111, F8, WS425_SN_,      OK  , 202, 197, 5, 5,   8.5,   8.5,   8.9,   4.4,   4.6,   5.2, 196.6,   6.4, 172.0,   3.6, 198.0,   6.4, 172.0,   2.0, 178.0,   4.4,   6.0,  0,   0.0,   1.2, CR3000_SN_,      OK  , "2012-09-21 20:02:30", "SN_1838", 12.91, 16.45, 17.06, 49.96,1001.1,  0.00,  0.00,2419.4, 432.0,   -4.4,   3.2, 206.6, S78D_SN_,      OK  ,64628.0,64977.0,   8.0, 211.6,   4.3, 207.1,   4.6,   5.4, 209.8,   3.2, 190.3,   5.4, 214.3,   1.6, 191.1,   3.8,  23.2,  0,   0.0,   0.8, PARS_SN ,      OK  ,  0.00, 147.7,    C,   -10.0,   9999,  19.0, 10059,     0,   0.0,   0.0,   0.0,   0.0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TB_SN_ ,      OK  ,   0.0,   0.0,   0.0,   0.0, GEONOR_SN_,      OK  ,  -0.2,  -0.2,   0.0,  -0.5, MP3000_SN_3031,      OK  , 13611, 09/21/12 23:52:03,   201, 290.8410,  54.5700, 992.6000, 224.9700,   0.0000, 13616, 09/21/12 23:52:52,   301,   2.006,   0.000,  -1.000, 13629, 09/21/12 23:53:40,   301,   2.153,   0.000,  -1.000, 13612, 09/21/12 23:52:49,   401, Zenith33, 290.841, 290.619, 290.324, 289.965, 289.594, 289.315, 289.019, 288.657, 288.252, 287.874, 287.473, 286.550, 285.484, 284.489, 283.557, 282.448, 281.549, 280.729, 279.510, 278.444, 277.386, 276.560, 275.714, 275.025, 274.243, 273.660, 272.269, 270.575, 269.615, 268.371, 267.229, 265.628, 264.201, 262.967, 261.651, 259.787, 258.405, 256.936, 255.301, 253.573, 251.715, 249.948, 248.309, 246.431, 244.513, 242.739, 240.876, 238.979, 237.113, 235.236, 233.310, 231.360, 229.586, 227.806, 226.248, 224.444, 222.997, 221.686, 13613, 09/21/12 23:52:50,   402, Zenith33,   8.112,   7.620,   7.356,   7.167,   7.001,   6.926,   6.905,   6.821,   6.749,   6.753,   6.634,   6.261,   5.949,   5.797,   5.612,   5.539,   5.345,   5.309,   5.308,   5.128,   4.854,   4.559,   4.412,   4.302,   4.119,   3.899,   3.280,   2.939,   2.634,   2.426,   2.251,   2.077,   1.768,   1.456,   1.191,   1.016,   0.836,   0.688,   0.572,   0.498,   0.420,   0.342,   0.315,   0.268,   0.247,   0.216,   0.169,   0.151,   0.117,   0.086,   0.079,   0.057,   0.043,   0.034,   0.027,   0.029,   0.025,   0.023, 13614, 09/21/12 23:52:50,   403, Zenith33,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.001,   0.002,   0.003,   0.004,   0.004,   0.005,   0.006,   0.006,   0.006,   0.005,   0.005,   0.006,   0.006,   0.006,   0.005,   0.004,   0.005,   0.007,   0.001,   0.001,   0.001,   0.001,   0.001,   0.001,   0.000,   0.001,   0.003,   0.001,   0.001,   0.002,   0.004,   0.001,   0.001,   0.004,   0.002,   0.002,   0.001,   0.000,   0.002,   0.000,   0.000,   0.002,   0.001, 13615, 09/21/12 23:52:51,   404, Zenith33,  56.270,  53.729,  53.026,  52.810,  52.940,  53.694,  54.346,  54.964,  55.335,  56.838,  57.384,  58.904,  60.251,  62.294,  63.354,  65.906,  66.386,  69.111,  73.093,  75.221,  75.959,  76.108,  77.720,  79.306,  80.117,  79.051,  73.398,  70.405,  73.031,  72.626,  69.891,  68.496,  69.016,  64.496,  60.284,  56.164,  50.403,  46.814,  43.598,  40.230,  38.220,  36.595,  37.270,  35.931,  35.872,  34.573,  34.382,  31.848,  30.184,  28.592,  27.367,  26.572,  25.385,  24.167,  22.947,  22.196,  20.102,  17.273, 13617, 09/21/12 23:53:37,   401, Angle Scan32(N), 290.841, 290.341, 290.135, 289.888, 289.601, 289.359, 289.063, 288.816, 288.596, 288.292, 287.907, 286.989, 286.151, 285.159, 283.948, 282.604, 281.604, 280.663, 279.693, 278.789, 278.079, 277.346, 276.519, 275.626, 274.793, 274.033, 272.555, 271.680, 270.758, 269.641, 268.433, 266.921, 265.443, 264.229, 263.036, 261.562, 260.179, 258.611, 257.035, 255.240, 253.437, 251.850, 250.007, 248.111, 246.297, 244.386, 242.365, 240.776, 239.021, 237.268, 235.613, 233.999, 232.464, 230.806, 229.090, 227.562, 226.043, 224.730, 13620, 09/21/12 23:53:38,   402, Angle Scan32(N),   8.160,   7.857,   7.577,   7.363,   7.180,   7.123,   7.047,   7.133,   7.134,   7.075,   7.083,   6.916,   6.715,   6.682,   6.530,   6.323,   5.999,   5.897,   5.845,   5.772,   5.604,   5.312,   5.007,   4.764,   4.590,   4.224,   3.621,   3.104,   2.680,   2.432,   2.241,   2.012,   1.820,   1.490,   1.207,   1.003,   0.830,   0.694,   0.557,   0.489,   0.417,   0.340,   0.290,   0.240,   0.203,   0.165,   0.148,   0.128,   0.105,   0.104,   0.077,   0.066,   0.051,   0.031,   0.026,   0.032,   0.027,   0.023, 13623, 09/21/12 23:53:39,   403, Angle Scan32(N),   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.001,   0.002,   0.003,   0.003,   0.003,   0.004,   0.005,   0.007,   0.006,   0.005,   0.005,   0.008,   0.007,   0.004,   0.003,   0.002,   0.004,   0.003,   0.001,   0.001,   0.001,   0.000,   0.001,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.000,   0.001,   0.002,   0.003,   0.000, 13626, 09/21/12 23:53:40,   404, Angle Scan32(N),  57.019,  55.193,  53.564,  53.315,  53.339,  53.281,  53.637,  55.162,  56.061,  56.732,  57.804,  59.747,  61.663,  65.110,  66.650,  67.988,  67.915,  70.569,  73.641,  75.918,  76.393,  76.266,  74.408,  74.010,  74.288,  73.384,  70.577,  66.022,  65.699,  65.979,  65.527,  66.482,  68.845,  60.866,  56.617,  53.351,  47.036,  41.541,  38.110,  35.401,  34.460,  33.999,  33.480,  31.319,  31.345,  31.507,  30.179,  28.661,  26.417,  26.580,  26.578,  27.422,  26.442,  25.451,  24.835,  25.084,  22.074,  20.811, 13618, 09/21/12 23:53:37,   401, Angle Scan32(S), 290.841, 290.626, 290.240, 289.821, 289.469, 289.065, 288.771, 288.341, 288.121, 288.010, 287.614, 286.667, 285.864, 284.613, 283.457, 282.245, 281.322, 280.393, 279.502, 278.463, 277.581, 276.853, 275.805, 274.735, 273.891, 273.092, 271.414, 270.019, 269.101, 267.951, 266.361, 264.487, 262.818, 261.826, 260.810, 259.275, 257.892, 256.162, 254.619, 252.395, 250.385, 248.765, 246.572, 244.208, 241.912, 239.723, 237.677, 235.897, 233.725, 231.819, 229.917, 228.090, 226.747, 225.073, 223.535, 222.356, 221.359, 220.467, 13621, 09/21/12 23:53:38,   402, Angle Scan32(S),   7.814,   6.994,   6.357,   5.945,   5.634,   5.442,   5.438,   5.371,   5.350,   5.230,   5.403,   4.970,   4.875,   4.949,   5.079,   5.089,   4.678,   4.723,   4.734,   4.826,   4.625,   4.731,   5.251,   5.544,   5.911,   6.282,   7.083,   7.490,   7.369,   6.637,   5.359,   3.880,   2.902,   1.757,   1.279,   1.035,   0.725,   0.560,   0.455,   0.361,   0.275,   0.255,   0.190,   0.162,   0.130,   0.122,   0.103,   0.103,   0.080,   0.080,   0.062,   0.061,   0.056,   0.033,   0.026,   0.032,   0.025,   0.020, 13624, 09/21/12 23:53:39,   403, Angle Scan32(S),   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.003,   0.002,   0.003,   0.003,   0.004,   0.006,   0.006,   0.005,   0.005,   0.007,   0.006,   0.003,   0.003,   0.002,   0.004,   0.003,   0.001,   0.001,   0.001,   0.000,   0.001,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.000,   0.000,   0.000,   0.000,   0.000,   0.001,   0.001,   0.000,   0.001,   0.002,   0.003,   0.000, 13627, 09/21/12 23:53:40,   404, Angle Scan32(S),  56.426,  52.621,  49.854,  47.596,  47.538,  48.077,  50.507,  49.331,  49.623,  49.122,  51.626,  50.226,  51.898,  55.446,  57.410,  61.732,  58.361,  60.002,  61.793,  65.138,  68.036,  74.196,  82.373,  85.787, 100.000, 100.000, 100.000, 100.000, 100.000, 100.000, 100.000, 100.000, 100.000,  85.190,  66.155,  53.728,  37.351,  23.545,  17.741,  14.367,  12.172,  13.330,  10.572,  10.516,   9.346,   8.075,   6.828,   5.445,   5.651,   5.252,   5.502,   6.274,   6.017,   6.092,   6.767,   6.991,   5.608,   4.837, 13619, 09/21/12 23:53:37,   401, Angle Scan32(A), 290.841, 290.480, 290.186, 289.854, 289.535, 289.214, 288.917, 288.581, 288.361, 288.152, 287.764, 286.828, 286.006, 284.883, 283.694, 282.416, 281.453, 280.518,
4

2 回答 2

2

您在这里有两个不同的操作。首先是行的选择,将自己限制为仅以字符串开头2012Sep并包含字符串FD12P, PARS(按此顺序)的行。

第二个是过滤这些行中的每一行,以仅保留日期和和之间的文本FDP12PARS不包括PARS本身)。

第一个操作可以用grep管道中的 a 完成,第二个操作可以用 a 完成sed

grep '^2012Sep.*, FD12P.*, PARS' infile.dat
    | sed -e 's/ .*, FD12P/, FD12P/'
          -e 's/, PARS.*$//'
    >outfile.dat

这取决于您应该检查的几件事。

  • 日期后紧跟一个空格;
  • 只有一个FDP12PARS在行中;
  • FD12PandPARS总是以(", "逗号、空格)开头。

如果其中任何一个结果不正确,您可能需要调整 和 的grep参数sed。如果违反了第二条规则,这尤其值得关注,因为您必须更详细地指定您希望它的行为方式。

以下记录显示了这一点:

pax> cat qq.in
2012Sep212357 23:56, AAA_YMDHMS, FD12P_S/N , blah, PARS, more blah
a dummy line which should not match
2012Sep212358 23:57, AAA_YMDHMS, FD12P_S/N , yada, PARS_xyzzy, more yada

pax> grep '^2012Sep.*FD12P.*, PARS' qq.in
...> | sed -e 's/ .*FD12P/, FD12P/' -e 's/, PARS.*$//'
2012Sep212357, FD12P_S/N , blah
2012Sep212358, FD12P_S/N , yada
于 2013-03-10T12:29:55.477 回答
1

您可以通过提供多个来分隔正则表达式-e

grep -e '^2012Sep' -e '^FD12P.*PARS$' file.dat

另外,从您在上一个答案中的最后一条评论中,我了解到您不仅想找到匹配的行,还想提取匹配的行。

使用 gnu grep,您可以使用以下-o标志:

grep -oe '^2012Sep' -e '^FD12P.*PARS$' file.dat

编辑:

假设您要查找以 2012Sep 开头并包含 FD12P 和 PARS 的所有行,并且只输出特定部分。sed在这种情况下更有意义:

sed -ne 's#^\(2012Sep[^ ]*\).*\(FD12P.*\)PARS.*#\1,\2#p' file.dat | sed -e 's#  *# #g'
  • -n告诉 sed 默认情况下不要回显行
  • p当行匹配时,该标志告诉 sed 输出行
  • 括号创建要保留的数据组
  • \1 和 \2 引用组
  • 我们匹配整行(我们想要的数据周围的.*),这意味着只有我们的替换将保留
于 2013-03-10T13:40:39.220 回答