Fetching columns from .csv file except last column

Hi,

i have below list of files so i just want the name of the files in one parameter and not the timestamp.
i want only GIDW_Dy_Tm_Seg_Sls_legacy_PL_0_0_ in variable of all files.

 GIDW_Dy_Tm_Seg_Sls_legacy_PL_0_0_20131001101800.csv
 GIDW_Dly_Sls_legacy_RO_0_0_20131001172001.csv
 GIDW_Dly_Sls_legacy_RO_0_0_20131001170502.csv
 GIDW_Dly_Sls_IT_0_0_20131001142013.csv
 GIDW_Dly_Sls_IT_0_0_20131001120323.csv
 GIDW_Dly_Pmix_PL_0_0_20131001114802.csv
 GIDW_Dly_Pmix_PL_0_0_20131001114301.csv
 GIDW_Dy_Tm_Seg_Sls_legacy_PL_0_0_20131001102800.csv
 GIDW_Dy_Tm_Seg_Sls_PT_0_0_20131001053026.csv
 GIDW_Dy_Tm_Seg_Sls_PT_0_0_20131001054026.csv

thanks in advance!!!

I do not understand what you are trying to do. The title of this thread says you want the last column in a comma separated values file; the body of the 1st message in this thread seems to say that you want the 1st (not last) part of the names (not contents) of the .csv files???

Then you say that you want the names of the files in one parameter??? Where does this parameter come from? What is a "variable of all files"?

Are you saying that after reading your list from standard input, you want a shell variable set to the value?:

GIDW_Dy_Tm_Seg_Sls_legacy_PL_0_0_ GIDW_Dly_Sls_legacy_RO_0_0_ GIDW_Dly_Sls_legacy_RO_0_0_ GIDW_Dly_Sls_IT_0_0_ GIDW_Dly_Sls_IT_0_0_ GIDW_Dly_Pmix_PL_0_0_ GIDW_Dly_Pmix_PL_0_0_ GIDW_Dy_Tm_Seg_Sls_legacy_PL_0_0_ GIDW_Dy_Tm_Seg_Sls_PT_0_0_ GIDW_Dy_Tm_Seg_Sls_PT_0_0_

yes i want only list of of names in the a .xls file ....i need it for renaming process ....so i will fect the names of files and add current timestamp to all the files using for loop ...

 perl -pe 's/_[0-9]{14}.csv\n/ /g' input_file

perl -pe 's/_[0-9]{14}.csv\n/ /g' filelist.xls
GIDW_Dly_Pmix_PL_0_0 GIDW_Dly_Pmix_PL_0_0 GIDW_Dly_Sls_IT_0_0 GIDW_Dly_Sls_IT_0_0 GIDW_Dly_Sls_legacy_RO_0_0 GIDW_Dly_Sls_legacy_RO_0_0 GIDW_Dy_Tm_Seg_Sls_legacy_PL_0_0 GIDW_Dy_Tm_Seg_Sls_legacy_PL_0_0 GIDW_Dy_Tm_Seg_Sls_PT_0_0 GIDW_Dy_Tm_Seg_Sls_PT_0_0

but i want the output it in different line ....

You're not making any sense?

What .xls file?

Without the timestamps, your filenames are not unique.

Other than changing the timestamp on the files, what do you want to do?

What do you want to happen to GIDW_Dly_Sls_legacy_RO_0_0_20131001172001.csv ? Do you just want to rename it changing the timestamp from 20131001172001 to the current time? (Note that if that is what you want, you could easily end up destroying some files using this method because your file names with the timestamps removed are not unique, and you may be able to rename several files in a second if you do this without creating a bunch of unneeded temporary files.)

i am using this command

awk -F "_" '{$(NF--)=""; print}' filelist.xls
GIDW Dly Pmix PL 0 0
GIDW Dly Pmix PL 0 0
GIDW Dly Sls IT 0 0
GIDW Dly Sls IT 0 0
GIDW Dly Sls legacy RO 0 0
GIDW Dly Sls legacy RO 0 0
GIDW Dy Tm Seg Sls legacy PL 0 0
GIDW Dy Tm Seg Sls legacy PL 0 0
GIDW Dy Tm Seg Sls PT 0 0
GIDW Dy Tm Seg Sls PT 0 0

but the "_" is missing in the files ....i need it too

_ is missing since you are setting Field Separator (FS) as _ So it's not getting printed

To be more clear here, renuk has the input field separator (FS) set to the underscore character but is using the default output field separator (OFS) which is a space character.

Try:

awk -F "_" '{$(NF--)=""; print}' OFS="_" filelist.xls

And PLEASE start putting in CODE tags on your own instead of expecting moderators to do it for you!

thanks a lot Akshay!!