kgolli
1
I am running an awk to verify all the memory settings for tomcat, and need to include path or directory in output ....
I am running:
awk '{ print $3 }' /opt/dir1/dir2/*/tomcat/bin/setenv.sh
Output results:
-Xms1024m
-Xmx1536m
-Xmx1536m
-Xmx1024m
-Xms1024m
-Xms1024m
-Xms512m
-Xms1024m
-Xms1536m
-Xms512m
-Xmx1024m
-Xmx1024m
-Xmx1024m
Is there something I can include in my command that would include the specific directory for '*' in the output?
Like so:
-Xmx1024m /dir3
Where dir3 would be * in /opt/dir1/dir2/*/tomcat/bin/setenv.sh
Or am I going about this completely wrong?
FILENAME would be /opt/dir1/dir2/whatever/tomcat/bin/setenv.sh.
awk '{ X=FILENAME; sub(/\/opt\/dir1\/dir2\//, "", X); sub(/\/tomcat\/bin\/setenv[.]sh/, "", X); print X, $3 }' /opt/dir1/dir2/*/tomcat/bin/setenv.sh
1 Like
RudiC
3
Please use code tags as required by forum rules!
man awk
:
awk '{print FILENAME}' /opt/dir1/dir2/*/tomcat/bin/setenv.sh
You can't find out the position of "*" in your input string as it will be expanded by the shell long before awk
gets hands on it.
kgolli
4
Thank you Corona688! Your solution worked for me!