Help with column delete from multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with column delete from multiple files
# 1  
Old 07-18-2017
Help with column delete from multiple files

sample .csv files with 7 columns.I want to delete the last column from each of the below files but retain their file names (1_ContractDocuments.csv,2_ContractDocuments.csv etc.)
There can be more files like 3_ContractDocuments.csv , 4_ContractDocuments.csv . Can you please help

source .csv files :

file 1 : 1_ContractDocuments.csv
Code:
CW2218471,testfile2.pdf,CW2218471/WS1033214854/Doc1043743258.pdf,Final Contract Document(s),,Published,1
CRW2218451,testfile1.pdf,CW2218471/CRW2218451/Doc1031919943.pdf,Main,,Published,1
CRW2218451,testfile3.pdf,CW2218471/CRW2218451/Doc1031919945.pdf,Main,,Published,1
CRW2218451,testfile4.pdf,CW2218471/CRW2218451/WS1031919946/Doc1031919947.pdf,Main,,Published,1

file 2 : 2_ContractDocuments.csv
Code:
CW22,testfile2.pdf,CW22/WS1033214854/Doc1043743258.pdf,Final Contract Document(s),,Published,1
CRW22,testfile1.pdf,CW22/CRW2218451/Doc1031919943.pdf,Main,,Published,1
CRW22,testfile3.pdf,CW22/CRW2218451/Doc1031919945.pdf,Main,,Published,1
CRW22,testfile4.pdf,CW22/CRW2218451/WS1031919946/Doc1031919947.pdf,Main,,Published,1


output expected :

file 1 : 1_ContractDocuments.csv (name of file same as before with last column deleted)
Code:
CW2218471,testfile2.pdf,CW2218471/WS1033214854/Doc1043743258.pdf,Final Contract Document(s),,Published
CRW2218451,testfile1.pdf,CW2218471/CRW2218451/Doc1031919943.pdf,Main,,Published
CRW2218451,testfile3.pdf,CW2218471/CRW2218451/Doc1031919945.pdf,Main,,Published
CRW2218451,testfile4.pdf,CW2218471/CRW2218451/WS1031919946/Doc1031919947.pdf,Main,,Published

file 2 : 2_ContractDocuments.csv (name of file same as before with last column deleted)
Code:
CW22,testfile2.pdf,CW22/WS1033214854/Doc1043743258.pdf,Final Contract Document(s),,Published
CRW22,testfile1.pdf,CW22/CRW2218451/Doc1031919943.pdf,Main,,Published
CRW22,testfile3.pdf,CW22/CRW2218451/Doc1031919945.pdf,Main,,Published
CRW22,testfile4.pdf,CW22/CRW2218451/WS1031919946/Doc1031919947.pdf,Main,,Published


Last edited by RudiC; 07-18-2017 at 03:07 PM..
# 2  
Old 07-18-2017
Any attempt / idea / thought from your side?

And, use code tags correctly: for code and data. DON'T enclose your entire post in code tags!
# 3  
Old 07-18-2017
yes I tried this . But it did not work ..

Code:
for FILE in *_ContractDocuments.csv
do  grp=$( echo $FILE | awk -F '_' '{print $1}' )
    cut -d ',' -f 1,2,3,4,5,6 < $FILE > $grp_ContractDocuments.csv
done

# 4  
Old 07-18-2017
you don't need a for loop.
Just an example to start with:
Code:
awk -F, 'NF--' OFS=, myFile.csv

# 5  
Old 07-18-2017
I want to keep the same file names .How do I get that with out a loop ? there are multiple source files
# 6  
Old 07-18-2017
not tested...
Code:
for FILE in *_ContractDocuments.csv
  { rm ${FILE}; awk -F, 'NF--' OFS=, > ${FILE}; } < ${FILE}
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

2. UNIX for Dummies Questions & Answers

Stack data from multiple files into one, with variable column files

Hello Gurus, Im new to scripting. Got struck with a file merge issue in Unix. Was looking for some direction and stumbled upon this site. I saw many great posts and replies but couldnt find a solution to my issue. Greatly appreciate any help.. I have three csv files -> Apex_10_Latest.csv,... (1 Reply)
Discussion started by: wamshi
1 Replies

3. Shell Programming and Scripting

Select multiple column from multiple files

Hi Friends, $ cat test1.txt emeka:1438 shelley:1439 dmeyer:1440 kurtarn:1441 abdul:1442 $ cat test2.txt 1:a 2:b 3:c 4:d $ cat test3.txt cat:dog:bat man:hot:cold (5 Replies)
Discussion started by: Jewel
5 Replies

4. UNIX for Dummies Questions & Answers

How To Delete Multiple Files At Once?

I Want to delete the following files together,what command should i pass for that? (Note:- All Start With .) .bash_logout .bashrc .bash_profile .rtorrent.rc ... (3 Replies)
Discussion started by: anime12345
3 Replies

5. Shell Programming and Scripting

Column extraction from multiple files to multiple files

I have roughly ~30 .txt files in a directory which all have unique names. These files all contain text arranged in columns separated by whitespace (example file: [#YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS TIDE #yr mo dy hr mn degT m/s m/s m sec ... (5 Replies)
Discussion started by: aozgaa
5 Replies

6. Shell Programming and Scripting

script to delete multiple files in remote machine

Requirement Several files in remote machines ought to be deleted via sh. Name of the files to be deleted are know Approach 1) script was written with ftp (requires credential) and delete command. File names were passed as array(iterated via for loop-with ftp+delete commands enclosed within... (1 Reply)
Discussion started by: vkalya
1 Replies

7. Shell Programming and Scripting

combine multiple files by column into one files already sorted!

I have multiple files; each file contains a certain data in a column view simply i want to combine all those files into one file in columns example file1: a b c d file 2: 1 2 3 4 file 3: G (4 Replies)
Discussion started by: ahmedamro
4 Replies

8. Shell Programming and Scripting

Script to delete all data from multiple files

its urgent!!!!!!111 i need a script which can delete data from multiple files. plz if anybody knows the script plz write a mail to me : (Email addresses are not allowed) (5 Replies)
Discussion started by: uni_ajay_r
5 Replies

9. UNIX for Dummies Questions & Answers

Need a script to delete multiple files

Hello, I am working with about 500,000 text files and 90% of them are duplicates. I need a way to delete the duplicate ones. The files are email messages with the following file name examples: 20040129-1457 This is the Subject line.txt 20040129-1457 This is the Subject line-1.txt... (3 Replies)
Discussion started by: navycow
3 Replies

10. UNIX for Dummies Questions & Answers

when I try to run rm on multiple files I have problem to delete files with space

Hello when I try to run rm on multiple files I have problem to delete files with space. I have this command : find . -name "*.cmd" | xargs \rm -f it doing the work fine but when it comes across files with spaces like : "my foo file.cmd" it refuse to delete it why? (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question