Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
Grammar, mostly
Source Link
jasonwryan
  • 74.9k
  • 35
  • 204
  • 230

iI have an awk script and iI have passed csva CSV file to it.

awk -f script.awk /home/abc/imp/asgd.csv 

What am iI doing is to get FILENAME within scriptscript.awk.awk,FILENAME give FILENAME gives me the whole path.As i As I am in awk iI cannot use basename FILENAME.

print FILENAME; /home/abc/imp/asgd.csv 

iI have tried with this within awk script.awkscript.awk

echo $FILENAME | awk -F"/" '{print $NF}' 

but I cannot execute this within script.awk,any help ,howscript.awk. How can iI get asgd.csvasgd.csv within an awk program,thanks.?

i have an awk script and i have passed csv file to it.

awk -f script.awk /home/abc/imp/asgd.csv 

What am i doing to get FILENAME within script.awk,FILENAME give me whole path.As i am in awk i cannot use basename FILENAME.

print FILENAME; /home/abc/imp/asgd.csv 

i have tried with this within awk script.awk

echo $FILENAME | awk -F"/" '{print $NF}' 

but cannot execute this within script.awk,any help ,how can i get asgd.csv within awk program,thanks.

I have an awk script and I have passed a CSV file to it.

awk -f script.awk /home/abc/imp/asgd.csv 

What am I doing is to get FILENAME within script.awk. FILENAME gives me the whole path. As I am in awk I cannot use basename FILENAME.

print FILENAME; /home/abc/imp/asgd.csv 

I have tried with this within script.awk

echo $FILENAME | awk -F"/" '{print $NF}' 

but I cannot execute this within script.awk. How can I get asgd.csv within an awk program?

Source Link
Aashu
  • 801
  • 4
  • 16
  • 25

Extract file name from path in awk program

i have an awk script and i have passed csv file to it.

awk -f script.awk /home/abc/imp/asgd.csv 

What am i doing to get FILENAME within script.awk,FILENAME give me whole path.As i am in awk i cannot use basename FILENAME.

print FILENAME; /home/abc/imp/asgd.csv 

i have tried with this within awk script.awk

echo $FILENAME | awk -F"/" '{print $NF}' 

but cannot execute this within script.awk,any help ,how can i get asgd.csv within awk program,thanks.