AWK command working different in Linux

Hi All
I have fired a command in linux

table=`echo ${file_name} | awk '{FS="/"; print $NF}' | awk '{FS="."; print $1}'`

where file_name has
/data/ds/dpr_ebicm_uat/backfill/temp/etl_app_info.csv
/data/ds/dpr_ebicm_uat/backfill/temp/etl_app_jobs.csv
/data/ds/dpr_ebicm_uat/backfill/temp/etl_ctrlmrmv_config.csv
/data/ds/dpr_ebicm_uat/backfill/temp/etl_filerename_config.csv
/data/ds/dpr_ebicm_uat/backfill/temp/etl_fileutil_config.csv
/data/ds/dpr_ebicm_uat/backfill/temp/etl_filewatcher_config.csv
/data/ds/dpr_ebicm_uat/backfill/temp/etl_formatter_config.csv

when i do

echo $table i get following value
/data/ds/dpr_ebicm_uat/backfill/temp/purge_table_config.csv

whereas i need only purge_table_config which refers to the table name.

But the same command gives me the correct output in unix. But now as our project is migrating we are using linux.
Could you all please help me to modify this command so that it gives the output as only purge_table_config which is only the table name.

Thanks

awk on many Linux distros is actually gawk.

gawk splits the line into fields when the line is read - resetting FS afterwards (i.e. inside a procedure) doesn't change the field splitting (which is correct POSIX, iirc).

You can either set FS inside BEGIN, or use -F.
e.g.

table=`echo ${file_name} | awk -F"/" '{print $NF}' | awk -F"." '{print $1}'`

With one awk command:

table=`echo ${file_name} | awk -F"[./]" '{print $(NF-1)}'

Thanks it worked,
I have another question
Could you please tell me the interpretation of following command as to what output would it give me in linux

echo "${VALUE}" | awk '{print index($0,"*")}'` -gt 0 ] && VALUE=`echo ${VALUE} | sed -e 's/"//g'

where VALUE=/data/ds/dpr_ebicm_uat/backfill/temp/etl_app_jobs.csv
I ran the command and it is giving me output as
0
0
0 likewise all zeros
I also need interpretation of following command

cat ${file_name} | awk 'NR>1' | while read data
value=`echo ${data} | awk '{if (substr($1,0,1) == "\047") gsub("^\047+|\047+$", "", $0); gsub("\047,\047"," ",$0); print}'`
i want to know what value will the value variable have.
 
where file_name contains the list of files mentioned earlier
/data/ds/dpr_ebicm_uat/backfill/temp/etl_app_info.csv 
/data/ds/dpr_ebicm_uat/backfill/temp/etl_app_jobs.csv 
/data/ds/dpr_ebicm_uat/backfill/temp/etl_ctrlmrmv_config.csv 
/data/ds/dpr_ebicm_uat/backfill/temp/etl_filerename_config.csv 
/data/ds/dpr_ebicm_uat/backfill/temp/etl_fileutil_config.csv 
/data/ds/dpr_ebicm_uat/backfill/temp/etl_filewatcher_config.csv 
/data/ds/dpr_ebicm_uat/backfill/temp/etl_formatter_config.csv 

Thanks

Part of the command appears to be missing? Before ` -gt 0 ]

Actually its the same

like

 
[ `echo "${VALUE}" | awk '{print index($0,"*")}'` -gt 0 ] && VALUE=`echo ${VALUE} | sed -e 's/"//g'`

I have taken this directly from the script, when i tried running it on linux its throwing me following error
-bash: 0: command not found
I also tried running this command separately VALUE=`echo ${VALUE} | sed -e 's/"//g'` it again throws a error like
-bash: command not found. Do these commands have a separate syntax in linux.
Please help me out with this. As the script is working different in linux enviornment

No, it isn't - the characters you previously missed off the front are rather important, since otherwise it's not valid syntax...

I had just missed out the starting bracket, else thats the only command.
Ok then atlease can you tell me what the index variable does. And why is the sed command throwing an error.

---------- Post updated at 09:51 AM ---------- Previous update was at 09:48 AM ----------

I guess i had just missed out the starting bracket, else there's nothing before that. Atleast can you tell me what does the index field in the awk command does. And why is the sed command

VALUE=`echo ${VALUE} | sed -e 's/"//g'`

failing in linux is there some other syntax.

I don't see anything obviously wrong with it. What error is it throwing?

Its throwing error like command not found

'like' command not found? What, exactly, does it say? Tell me word for word, letter for letter, keystroke for keystroke.