Fetching columns from .csv file except last column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fetching columns from .csv file except last column
# 1  
Old 10-22-2013
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.

Code:
 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!!!

Last edited by Don Cragun; 10-22-2013 at 02:48 AM.. Reason: Add CODE and ICODE tags
# 2  
Old 10-22-2013
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?:
Code:
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_

# 3  
Old 10-22-2013
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 ...
# 4  
Old 10-22-2013
Code:
 perl -pe 's/_[0-9]{14}.csv\n/ /g' input_file


Last edited by greet_sed; 10-22-2013 at 04:14 AM.. Reason: Tested code.
# 5  
Old 10-22-2013
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 ....

Last edited by renuk; 10-22-2013 at 04:19 AM..
# 6  
Old 10-22-2013
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.)
# 7  
Old 10-22-2013
i am using this command
Code:
awk -F "_" '{$(NF--)=""; print}' filelist.xls

Code:
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

Last edited by Don Cragun; 10-22-2013 at 04:45 AM.. Reason: Added CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Fetching 1st Column and Last n Columns

I am trying to fetch 1st column and last 10 columns.The code I am using is working fine but after using the code then output file becomes space delimited not tab delimited. awk 'BEGIN {OFS="\t"}{printf("%s\t",$1)}{for(i=NF-9; i<=NF; i++) {printf("%s\t",$i)};printf "\n" } ' inputfile ... (11 Replies)
Discussion started by: Nina2910
11 Replies

2. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

3. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

4. Linux

To get all the columns in a CSV file based on unique values of particular column

cat sample.csv ID,Name,no 1,AAA,1 2,BBB,1 3,AAA,1 4,BBB,1 cut -d',' -f2 sample.csv | sort | uniq this gives only the 2nd column values Name AAA BBB How to I get all the columns of CSV along with this? (1 Reply)
Discussion started by: sanvel
1 Replies

5. Shell Programming and Scripting

Fetching values in CSV file based on column name

input.csv: Field1,Field2,Field3,Field4,Field4 abc ,123 ,xyz ,000 ,pqr mno ,123 ,dfr ,111 ,bbb output: Field2,Field4 123 ,000 123 ,111 how to fetch the values of Field4 where Field2='123' I don't want to fetch the values based on column position. Instead want to... (10 Replies)
Discussion started by: bharathbangalor
10 Replies

6. Shell Programming and Scripting

Need help with awk statement to break nth column in csv file into 3 separate columns

Hello Members, I have a csv file in the format below. Need help with awk statement to break nth column into 3 separate columns and export the changes to new file. input file --> file.csv cat file.csv|less "product/fruit/mango","location/asia/india","type/alphonso" need output in... (2 Replies)
Discussion started by: awk-admirer
2 Replies

7. Shell Programming and Scripting

How to delete a column/columns of a CSV file which has cell values with a string enclosed in " , "?

How can I delete a column from a CSV file which has comma separated value with a string enclosed in double quotes and a comma in between? I have a file 44.csv with 4 lines including the header like the below format: column1, column2, column3, column 4, column5, column6 12,455,"string with... (6 Replies)
Discussion started by: dhruuv369
6 Replies

8. Shell Programming and Scripting

Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks

Hi Friends, I have come across some files where some of the columns don not have data. Key, Data1,Data2,Data3,Data4,Data5 A,5,6,,10,, A,3,4,,3,, B,1,,4,5,, B,2,,3,4,, If we see the above data on Data5 column do not have any row got filled. So remove only that column(Here Data5) and... (4 Replies)
Discussion started by: ks_reddy
4 Replies

9. UNIX for Advanced & Expert Users

Help in Deleting columns and Renaming Mutliple columns in a .Csv File

Hi All, i have a .Csv file in the below format startTime, endTime, delta, gName, rName, rNumber, m2239max, m2239min, m2239avg, m100016509avg, m100019240max, metric3min, m100019240avg, propValues 11-Mar-2012 00:00:00, 11-Mar-2012 00:05:00, 300.0, vma3550a, a-1_CPU Index<1>, 200237463, 0.0,... (9 Replies)
Discussion started by: mahi_mayu069
9 Replies

10. Shell Programming and Scripting

Fetching data from .csv file

Hi Experts, I have created a table with columns as empname,empid,phone,shiftname. Now I am having a .csv file format which contains the shift datas of the employees. I have to fetch this file and compare with the table I created to send an alert to the specified user. (2 Replies)
Discussion started by: micky3112
2 Replies
Login or Register to Ask a Question