Deleting a column in multiple files that are comma separated

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting a column in multiple files that are comma separated
# 1  
Old 11-01-2009
Deleting a column in multiple files that are comma separated


I have a directory that contains say 100 files named sequencially like input_1.25_50_C1.txt

an example of the content in each of the file is:

"cgd1_10" "cgd1_10" 0.938962779873022
"cgd1_1860" "cgd1_1860" 0.728179501334915
"cgd1_2500" "cgd1_2500" 0.751709755780061
"cgd1_2560" "cgd1_2560" 0.8086690400501
"cgd1_2640" "cgd1_2640" 0.750586302165714
"cgd1_2800" "cgd1_2800" 0.954020921349781
"cgd1_290" "cgd1_290" 0.757355995574881
"cgd1_2950" "cgd1_2950" 0.558344549451538
"cgd1_3010" "cgd1_3010" 0.667420188529345
"cgd1_50" "cgd1_50" 0.545172222953814
"cgd2_1000" "cgd2_1000" 0.944926355001402
"cgd2_1690" "cgd2_1690" 0.861817882469458
"cgd3_1820" "cgd3_1820" 0.817150133730118
"cgd3_2150" "cgd3_2150" 0.553855831143878
"cgd4_2220" "cgd4_2220" 0.577452218116135

I want to delete the second & third column of each file, make the file tab delimited and replace the column heading "NAME" in the first column as [Gene]

Is there a way in awk or shell programming to do this at a directory level; without openning each file and editing it.

Please let me know.

Lucky Ali

Last edited by Lucky Ali; 11-01-2009 at 04:55 PM..
# 2  
Old 11-01-2009
I think I am missing something here as usual.

Your input file seems to only have 3 columns, if you want to delete 2 and 3 what is left to delimit with tabs? You also say it is coma delimited but I see no coma's....
# 3  
Old 11-01-2009
Forget about the tab delimit and comma separated. It was my mistake. I just wanted the first column with out enclosed with " " and change the heading for all the files in the Directory.

---------- Post updated at 02:39 PM ---------- Previous update was at 02:37 PM ----------

Need to delete column 2 and 3

---------- Post updated at 02:45 PM ---------- Previous update was at 02:39 PM ----------

Also if I import the above file in excel, I have to use ',' as delimter
# 4  
Old 11-01-2009
suggestion to get the first column of each file
for FILE in *.txt
    NEWFILE=new-$FILE # It's an example
    cut -d' ' -f1 $FILE > $NEWFILE

# 5  
Old 11-01-2009
I type this:

for FILE in *.txt; do NEWFILE=new-$FILE; cut -d ' ' -f1 $FILE > $NEWFILE; done

but it just copied the file like that into another file with the new name

Let me know what mistake I did
# 6  
Old 11-01-2009
Option for cut : -d [delimiter] i've put a space between the quotes : -d ' '.
-f [field number(s)].
if You don't specify -d, the [TAB] will be used as delimiter. In any case the delimiter must be a single caracter.
It seems that you did'nt put anything between the quotes.
# 7  
Old 11-01-2009
I specified a space in between the quotes and tried again. But still it just copying the file in a new file; not getting the first column. Let me know if you need any other info
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

2. Shell Programming and Scripting

Convert column to quote and comma separated row

Hi, I have a list of tables in a file.txt C_CLAIM C_HLD C_PROVIDER I want the output to be 'C_CLAIM','C_HLD','C_PROVIDER' Currently I'm usin awk and getting output which is almost correct but still has minor defects awk -vORS="','" '{ print $1 }' file.txt The output of... (4 Replies)
Discussion started by: wahi80
4 Replies

3. Shell Programming and Scripting

Combining multiple block of lines in one comma separated line

Hi Everyone, On my Linux box I have a text file having block of few lines and this block lines separated by one blank line. I would like to format and print these lines in such a way that this entire block of lines will come as single comma separated line & again next block of lines in next... (7 Replies)
Discussion started by: gr8_usk
7 Replies

4. Shell Programming and Scripting

Make multiple lines into single quoted comma separated Linux

Hi, I want to change a file file1.txt: 1234 3456 2345 6789 3456 2333 4444 As, file2.txt in Linux: '1234','3456','2345','6789','3456','2333','4444' Could someone please help me. (Single liner sed, awk will be welcome!) (7 Replies)
Discussion started by: wiweq05
7 Replies

5. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

6. Shell Programming and Scripting

Need Help - comma inside double quote in comma separated csv,

Hello there, I have a comma separated csv , and all the text field is wrapped by double quote. Issue is some text field contain comma as well inside double quote. so it is difficult to process. Input in the csv file is , 1,234,"abc,12,gh","GH234TY",34 I need output like below,... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

7. Shell Programming and Scripting

Assigning Multiple Comma Separated IP's To A Bash Array

I am in the process of creating a BASH shell scripts for a project at work. So the scenario is as such: I have a file with each line entry separated by ':' ... (3 Replies)
Discussion started by: metallica1973
3 Replies

8. Homework & Coursework Questions

Find the files and make them comma separated files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi All, I am new to unix, my requirement is like need to find the files like DATA_FUNCTION* and put those... (1 Reply)
Discussion started by: madsongtel
1 Replies

9. Shell Programming and Scripting

Finding difference in two comma separated files in UINX

Dear All, I have requirement like this: I have 2 camma seperated files file1: 1,aaa,bbb,ccc, 2,bbb,ccc,ddd, 3,ccc,ddd,eee, file2: 1,aaa,bbb,ccc, 2,bbb,ddd,ddd, 3,ccc,ddd,eee, my requirement is I should get message in the out put like: There is a difference in 3 rd filed in... (2 Replies)
Discussion started by: mymoto
2 Replies

10. UNIX Desktop Questions & Answers

Unix Comma Separated to Excel Column

I would like to copy 2 parts of a csv file from Unix to an XL sheet. However to save time I do not want to format the column ever time I cut and paste into XL(Text2Column). I've used awk -F, '{Print $1, $2....}'. Is there a script or code that can automatically format the csv for XL columns? ... (3 Replies)
Discussion started by: ravzter
3 Replies
Login or Register to Ask a Question