Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

linux - awk 'FNR == 2 {print}' issue

I have some task on which i need to know the install date of WLS which is located in second row of file called envVars.properties which is located in /opt/weblogic1221/wlserver_12.2.1/installation/install/envVars.properties. I have server which has multiple versions of WL there for I use * in /opt/weblogic*/wlserver*/.... But when I run cat /opt/weblogic*/wlserver*/installation/install/*.properties| awk 'FNR == 2 {print}' I get only 1 result (for the first file it finds).

See:

[root@server090 ~]# cat /opt/weblogic*/wlserver*/installation/install/*.properties| awk 'FNR==2{print}'
#Mon Feb 02 14:47:02 IST 2015

Without awk:

[root@server90 ~]# cat /opt/weblogic*/wlserver*/installation/install/*.properties
#Copyright (c) 1999, {0}, Oracle. All rights reserved.
#Mon Feb 02 14:47:02 IST 2015
JAVA_HOME_CCR=/usr/java/jdk1.7.0_72
#Copyright (c) 1999, 2016, Oracle. All rights reserved.
#Mon Feb 06 15:35:50 IST 2017
JAVA_HOME_CCR=/usr/java/jdk1.8.0_102

There are 2 files as you can see:

[root@server90 ~]# ll /opt/weblogic*/wlserver*/installation/install/*.properties
-rwxr-xr-x. 1 oracle dba 121 Feb  2  2015 /opt/weblogic1213/wlserver_12.1.3/installation/install/envVars.properties
-rwxrwxrwx. 1 oracle dba 123 Oct 20  2017 /opt/weblogic1221/wlserver_12.2.1/installation/install/envVars.properties

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Don't "cat through to awk", just specify the files after the awk statement and so:

awk 'FNR == 2 {print}' /opt/weblogic*/wlserver*/installation/install/*.properties

Using cat is needless and it will merge all input files into one single output, so awk will just see one input file (FNR can only match once, then).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...