我有一个包含多个内容的文件,如:
Create initial parsimony tree by phylogenetic likelihood library (PLL)... 0.022 seconds
Perform fast likelihood tree search using LG+I+G model...
Estimate model parameters (epsilon = 5.000)
Perform nearest neighbor interchange...
Estimate model parameters (epsilon = 1.000)
1. Initial log-likelihood: -30833.549
Optimal log-likelihood: -30833.420
Proportion of invariable sites: 0.016
Gamma shape alpha: 2.035
Parameters optimization took 1 rounds (0.226 sec)
Time for fast ML tree search: 2.912 seconds
NOTE: ModelFinder requires 64 MB RAM!
ModelFinder will test up to 546 protein models (sample size: 1544) ...
No. Model -LnL df AIC AICc BIC
1 LG 31317.712 31 62697.424 62698.736 62863.030
2 LG+I 31170.012 32 62404.024 62405.422 62574.972
3 LG+G4 30870.402 32 61804.803 61806.201 61975.751
4 LG+I+G4 30833.404 33 61732.808 61734.294 61909.098
5 LG+R2 30881.301 33 61828.602 61830.088 62004.892
6 LG+R3 30831.187 35 61732.374 61734.045 61919.349
Akaike Information Criterion: VT+F+R4
Corrected Akaike Information Criterion: VT+F+R4
Bayesian Information Criterion: VT+F+R4
Best-fit model: VT+F+R4 chosen according to BIC
other content....我想使用bash命令在部件后面存储元素:
Bayesian Information Criterion:在一个名为: The_variable的变量中。
到目前为止我试过:
The_variable="$(grep 'Bayesian Information Criterion:' the_file.txt)"这给了我所有的grep线
echo $The_variable
Bayesian Information Criterion: VT+F+R4但我希望它只存储VT+F+R4部分。
为了隔离这部分,我尝试了:
sed 's@.*: @@g' $VAR知道吗?
发布于 2022-11-22 07:45:46
在awk中比较容易
awk -F ' *: *' '$1 == "Bayesian Information Criterion" {print $2}' file
VT+F+R4
# to save this in a variable:
myvar=$(awk -F ' *: *' '$1 == "Bayesian Information Criterion" {print $2}' file)此gnu-grep解决方案还将与\K一起工作。
grep -oP 'Bayesian Information Criterion:\h*\K.+' file
VT+F+R4或者这个sed
sed -n 's/Bayesian Information Criterion: *//p' file
VT+F+R4发布于 2022-11-22 07:45:39
您可以使用awk打印所需的内容。默认情况下,分隔符是空格,所以在您的情况下,awk '{ print $4 }'将执行这项工作。
➜ echo 'Bayesian Information Criterion: VT+F+R4' | awk '{ print $4 }'
VT+F+R4https://stackoverflow.com/questions/74529005
复制相似问题