简体   繁体   中英

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}' 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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM