Include pathname in awk output?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Include pathname in awk output?
# 1  
Old 02-25-2015
Include pathname in awk output?

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:
Code:
awk '{ print $3 }' /opt/dir1/dir2/*/tomcat/bin/setenv.sh

Output results:
Code:
-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:
Code:
-Xmx1024m /dir3

Where dir3 would be * in /opt/dir1/dir2/*/tomcat/bin/setenv.sh

Or am I going about this completely wrong? :/

Last edited by Scrutinizer; 02-25-2015 at 01:09 PM.. Reason: code tags
# 2  
Old 02-25-2015
FILENAME would be /opt/dir1/dir2/whatever/tomcat/bin/setenv.sh.

Code:
awk '{ X=FILENAME;  sub(/\/opt\/dir1\/dir2\//, "", X); sub(/\/tomcat\/bin\/setenv[.]sh/, "", X);  print X, $3 }' /opt/dir1/dir2/*/tomcat/bin/setenv.sh

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 02-25-2015
Please use code tags as required by forum rules!

man awk:
Quote:
7. Builtin-variables
The following variables are built-in and initialized before program execution.
.
.
.
FILENAME name of the current input file.
Code:
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.
# 4  
Old 02-25-2015
Thank you Corona688! Your solution worked for me!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - using variables in pattern which contain full pathname

Hello. I would like to make this bash command working. In the following code, the bash variable 'ZYPPER_LOCAL_REP' contain a full pathname like '/path/to/path/somewhere' The command list all available repositories, search for the string 'zipper_local' then on the same line search for... (4 Replies)
Discussion started by: jcdole
4 Replies

2. Shell Programming and Scripting

awk to create separate files but not include specific field in output

I am trying to use awk to create (in this example) 3 seperate text file from the unique id in $1 in file, if it starts with the pattern aa. The contents of each row is used to populate each text file except for $1 which is not needed. It seems I am close but not quite get there. Thank you :). ... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Include information in certain columns using grep and awk

HI all, I have data in a file that looks like this: 1 HOW _ NNP NNP _ 3 nn _ _ 2 DRUGS _ NNP NNP _ 3 nn _ _ 3 ACT _ NNP NNP _ 0 null _ _ 4 : _ ... (3 Replies)
Discussion started by: owwow14
3 Replies

4. Shell Programming and Scripting

awk regex- include text

Hi I am trying to filter some data using awk. I have a statement- awk 'BEGIN { FS = "\n" ; RS = "" } { if ( $6 = "City: " ) { print "City: Unknown" } else { print $6 } }'` The $6 values are City: London City: Madrid City: City: Tokyo This expression seems to catch all the lines... (4 Replies)
Discussion started by: jamie_123
4 Replies

5. Shell Programming and Scripting

How can I get sed to include backslash and 'f' in the output

Both of these fail. One has two form feeds, the second form leaves all the backslashes. bold='\(code\|command\|var\|samp\|option\|strong\)' sed -e "s;@${bold}{"'\(*\)};\fB\2\fP;g' sed -e "s;@${bold}{"'\(*\)};\\fB\2\\fP;g' Obviously, I'm trying to change texi markup into man page markup, but it... (3 Replies)
Discussion started by: bkorb
3 Replies

6. Shell Programming and Scripting

Need to include two more columns in the file using awk

Hi, I have a input file with many records as below: 1J4RR4GG0BC508200 68646 1 N M i want my output file to be like with columns included dgismdh and timestamp : Example: 1J4RR4GG0BC508200 68646 1 N M dgismdh 2012-02-21 07:22:25.98591 How to do it.can we do using awk? Pls help. (6 Replies)
Discussion started by: sonam273
6 Replies

7. Shell Programming and Scripting

how to include the missing column in the original file using awk

Hi Experts, The content of the raw file: date,nomsgsent,nomsgnotdeliver,nomsgdelay 201003251000,1000,1,2 201003251000,900,0,0 201003251000,1450,0,0 201003251000,1230,0,0 However, sometimes, the column will missing in the raw files: e.g. date,nomsgsent,nomsgdelay... (8 Replies)
Discussion started by: natalie23
8 Replies

8. Shell Programming and Scripting

Include Line Before Pattern Using Sed / Awk

Hi, I have a sql file that runs something like this vi Test.sql REVOKE EXECUTE ON DEMO_USER.SQC_SAMP FROM PUBLIC; REVOKE EXECUTE ON DEMO_USER.SQC_SAMP FROM DEMO_READ; REVOKE SELECT ON DEMO_USER.DEMO_NOMINEE_TEST FROM DEMO_READ; REVOKE EXECUTE ON DEMO_USER.SQC_SAMP FROM... (3 Replies)
Discussion started by: rajan_san
3 Replies

9. Shell Programming and Scripting

how to include field in the output filename of awk

Im using awk and I want the output filename to contain the first field of the input file. Ex. 1 dddd wwwww 1 eeeee wwww 1 wwww eerrrr 2 eeee eeeeee I want the output files to be xxx1 and xxx2 Thank you (4 Replies)
Discussion started by: yahyaaa
4 Replies

10. UNIX for Dummies Questions & Answers

How to include 'date' in my awk?

Hi, I have problem in including date in side awk, my code as follows: performace=performace.txt reporttime=`date` cat $performace | grep "testString" | awk '{ if ($3 > 20 ){print $reporttime $1 $2 $3}}' >> $rpt $reporttime is not reflecting properly in my report file($rpt)? how to... (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question