linux 获取字符所在列

linux 获取字符所在列

总是正向取值,这里来个反向取值。

因为不常用容易忘记,记录一下

使用awk命令,及内置for、if函数

#定位时间所在列表
[root@hecs-299586 ~]# date $date|awk '/[0-9]:[0-9][0-9]:[0-9][0-9]/ {for (i=1;i<=NF;i++) if($i ~/[0-9]:[0-9][0-9]:[0-9][0-9]/) print "第"i"列"}'
第5列

https://qnimg.ffing.cn/wp-content/uploads/2022/04/image-4.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

也可以用来定位文件中需要查找的列并输出

#config.xml文件内容如下 
<?xml version="1.0" standalone="yes" ?>
<!-- Copyright (c) 1999, 2019, Oracle and/or its affiliates.
All rights reserved. -->
<!-- Do not modify the contents of this file by hand. -->
<!-- Note: If there are any xml tools listed for suppression, the suppression shall be ignored and the xml tools shall be considered for execution during installation -->
<CONFIG_LIST>
<COMP NAME="oracle.server" VER="19.0.0.0.0" PLAT="Linux">
   <CT NAME="configtool1" NAME_ID="configtool1_ALL" DESC_ID="configtool1_DESC_ALL" LOC="" AGGREGATE_NAME="oracle.server.19_0_0_0_0.xml" CLS_NAME="" PLAT="Linux"/>
</COMP>
<COMP NAME="oracle.ons.ic" VER="19.0.0.0.0" PLAT="Linux">
   <CT NAME="configtool1" NAME_ID="configtool1_ALL" DESC_ID="configtool1_DESC_ALL" LOC="" AGGREGATE_NAME="oracle.ons.ic.19_0_0_0_0.xml" CLS_NAME="" PLAT="Linux"/>
</COMP>
<COMP NAME="oracle.has.common" VER="19.0.0.0.0" PLAT="Linux">
   <CT NAME="configtool1" NAME_ID="configtool1_ALL" DESC_ID="configtool1_DESC_ALL" LOC="" AGGREGATE_NAME="oracle.has.common.19_0_0_0_0.xml" CLS_NAME="" PLAT="Linux"/>
</COMP>
<COMP NAME="oracle.assistants.netca.client" VER="19.0.0.0.0" PLAT="Linux">
   <CT NAME="configtool1" NAME_ID="configtool1_ALL" DESC_ID="configtool1_DESC_ALL" LOC="" AGGREGATE_NAME="oracle.assistants.netca.client.19_0_0_0_0.xml" CLS_NAME="" PLAT="Linux"/>
</COMP>
</CONFIG_LIST>

#从/home/oracle/oracle-install安装文件中查找出配置文件,并输出版本号
[root@ffing ~]# find /home/oracle/oracle-install -type f -name config.xml |xargs grep -i "oracle.server.*ver"|awk '{for(i=1;i<=NF;i++) if($i ~ /[0-9].[0-9].[0-9].[0-9]/) print $i}'|awk -F"\"" '{print $2}'
19.0.0.0.0
good good study, day day up!

发表评论

textsms
account_circle
email

linux 获取字符所在列
总是正向取值,这里来个反向取值。 因为不常用容易忘记,记录一下 使用awk命令,及内置for、if函数 #定位时间所在列表 [root@hecs-299586 ~]# date $date|awk '/ …
扫描二维码继续阅读
2022-04-23