How to delete columns with numbers in an excel file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to delete columns with numbers in an excel file?
# 1  
Old 12-11-2012
How to delete columns with numbers in an excel file?

Dear all,
I have one file (see below) with more then 100 columns and 2500 rows, and need only column which has GType in label with Alphabets, please help me to remove these columns with numbers.
input file is

Code:
         n.201.GType    n-201.Theta    n-201.R   n_1.GType    n_1.Theta     n_1.R          n_7.GType      n_7.Theta        n_7.R           
BB                             0.823115       1.23659                   BB       0.791365      1.274946                  AB          0.441334         1.666898           
AA            0.02399     1.526078                               AA        0.021785     1.578031                 AA          0.013456        1.527924

output should be

Code:
         n_201.GType   n_1.GType   n_7.GType        
BB               BB         AB 
          AA               AA         AA

thanks

Last edited by Scott; 12-11-2012 at 12:55 PM.. Reason: Code tags
# 2  
Old 12-11-2012
Is this an excel file or a flat file?

If a flat file, what separates the columns? Tabs?

Please try posting your data again, your lack of code tags and attempts at spacing without them have thrown your table well out of whack.
# 3  
Old 12-11-2012
try:
Code:
awk '{for (i=1; i<=NF; i++) if ($i ~ /GType/)c[i]=i;} {for (i=1; i<=NF; i++) $i=(c[i])?$i:"";}1' infile

# 4  
Old 12-11-2012
Code:
awk '{for (i=1;i<=NF;i++) if ($i~/GType/||$i~/^[a-zA-Z]*$/) printf $i "\t";printf RS}' infile

n.201.GType     n_1.GType       n_7.GType
BB      BB      AB
AA      AA      AA

# 5  
Old 12-12-2012
Dear all,

i am sorry, but the both commands are not working for my file,
should I use them in Linux, as I tried in cygwin,
and Corona, yes I have this file in excel as well as in a tab delimited text file
waiting for your help
my file name is data table.txt or data table.xlsx
Regards

---------- Post updated at 10:19 AM ---------- Previous update was at 09:55 AM ----------

Dear Corona, here I upload my text delimited file for your kind consideration, (with in the code) only seven columns, first row is label and first column is names of samples

Code:
Name    n_410.GType    n_410.Theta    n_410.R    n_14.GType    n_014.Theta    n_14.R
B-80011558140-269    BB    0.8585083    1.182597    NC    0.04133479    0.3816845    AB    0.5569273    1.312853    BB    0.8443609    1.156271
B-80011565932-735    AA    0.02112507    1.547318    AA    0.02052359    1.452008    AA    0.02342339    1.444604    AA    0.01875894    1.540271
B-80011565932-883    BB    0.9910369    1.219364    BB    0.9829392    1.228494    BB    0.9917964    1.207549    BB    0.9896955    1.228145
B-80011568019-475    BB    0.9941319    0.8715777    BB    0.9845733    0.8617675    BB    0.9956517    0.8734978    NC    1.2038809    1.890736

Best Rgards

AAWT

---------- Post updated at 05:58 PM ---------- Previous update was at 10:19 AM ----------

hello
I used this command
Code:
awk '{for (i=1;i<=NF;i++) if ($i~/GType/||$i~/^[a-zA-Z]*$/) printf $i "\t";printf RS}' Data_Table.txt>Gtype.txt

and got only one row with the labels of column with Gtype, but not the whole column with AA,,,etc
please also consider that first column is name for rows

Best REgards

AAWT
# 6  
Old 12-12-2012
let me guess.

Code:
awk 'NR==1{for (i=1;i<=NF;i++) if ($i~/GType/) a[i]}
     {printf $1 FS; for (i=2;i<=NF;i++) if (i in a) printf $i FS;printf RS}' Data_Table.txt

Name n_410.GType n_14.GType
B-80011558140-269 BB NC
B-80011565932-735 AA AA
B-80011565932-883 BB BB
B-80011568019-475 BB BB

# 7  
Old 12-13-2012
I used following command

Code:
awk 'NR==1{for (i=1;i<=NF;i++) if ($i~/GType/) a[i]}{printf $1 FS; for (i=2;i<=NF;i++) if (i in a) printf $i FS;printf RS}' Data_Table.txt >Gtypes.txt

out put came with only first row with names.Gtype, and no other data column or row

Regards

AAWT
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading specific range of columns in an Excel file

Hi All, I want to read an excel file. PFA excel, I want to read the cloumn from A to G and the V to AH starting from Row number 3. Please help me on this. (7 Replies)
Discussion started by: Abhisrajput
7 Replies

2. Shell Programming and Scripting

Need specific columns in a log file as excel.

Hi All... I am in need of few columns from a log file.. in .xls file... below is what i have tried. my log file has 16 colums with " ; " as delimiter, but i need randomn columns 1 2 3 4 5 6 10 11 16 in an excel. I tried to awk the columns with delimiter ; and it worked, below is the log... (5 Replies)
Discussion started by: nanz143
5 Replies

3. Shell Programming and Scripting

Adding (as in arithmetic) to numbers in columns in file, and writing new file with new numbers

Hi again. Sorry for all the questions — I've tried to do all this myself but I'm just not good enough yet, and the help I've received so far from bartus11 has been absolutely invaluable. Hopefully this will be the last bit of file manipulation I need to do. I have a file which is formatted as... (4 Replies)
Discussion started by: crunchgargoyle
4 Replies

4. UNIX for Dummies Questions & Answers

Urgent_need to delete columns with numbers

Dear all, I have one file (see below) with more then 100 columns, and need only column which has GType in label with Alphabets, please help me to remove this columns with numbers. input file is n.201.GType n-201.Theta n-201.R n_1.GType n_1.Theta n_1.R n_7.GType ... (1 Reply)
Discussion started by: AAWT
1 Replies

5. UNIX for Dummies Questions & Answers

To compare first two columns in an excel file

Hi All, i have a excel sheet with two columns as below. column1 column2 100 100 200 300 300 400 400 400 500 600 i need to compare the values these two columns and the output should be printed in the third column...if these values are equal the output should be green and if these... (2 Replies)
Discussion started by: arunmanas
2 Replies

6. Shell Programming and Scripting

How to sort columns in excel(csv) file

i want sort columns with headers based on another file headers file1 eg: i'm having an empty file with only coumn names like lastname firstname title expirydate stlcno status etc... another file with same column names and some other as well but in different order... file2 eg:firstname... (2 Replies)
Discussion started by: Man83Nagesh
2 Replies

7. UNIX for Dummies Questions & Answers

Command to delete numbers at beginning of txt file line

Hello. I have the following issue: my txt file has the following format: train/dr4/fklc0/sx175.txt 0 80282 Severe myopia contributed to Ron's inferiority complex. train/dr4/fklc0/sx355.txt 0 42906 Dolphins are intelligent marine mammals. train/dr4/fklc0/sa2.txt awk 'NR%2==0' test1.txt >... (4 Replies)
Discussion started by: li_bi
4 Replies

8. Shell Programming and Scripting

Delete rows based on line numbers in a file

I have to find the number of rows in a file and delete those many rows in another file. For example, if I have 3 rows in a file A, i have to delete first 3 rows in anothe file B, I have the code, it works as standalone, when I merge this with m application (c with unix), it doesnt work. ... (2 Replies)
Discussion started by: Muthuraj K
2 Replies

9. Shell Programming and Scripting

how to convert fields from a text file to excel columns

i have this file which has the following contents: ,-0.3000 ,-0.3000 ,-0.3000 ,-0.9000 ,-0.9000 ,-0.9000 i would like to get this: -0.3-0.9-0.3-0.9-0.3-0.9 so far i am trying: awk '{for(i=1; i<=NF; i++) {printf("%f\n",$i)}}' test1 > test2 any help... (4 Replies)
Discussion started by: npatwardhan
4 Replies

10. Shell Programming and Scripting

use awk to read randomly located columns in an excel file

Hi, I have an excel file that have a random count of columns/fields and what im trying to do is to only retrieve all the rows under 2 specific field headers. I can use the usually command for awk which is awk 'print{ $1 $2}' > output.txt, but the location of the 2 specific field headers is... (9 Replies)
Discussion started by: mdap
9 Replies
Login or Register to Ask a Question