How to sort columns in excel(csv) file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to sort columns in excel(csv) file
# 1  
Old 08-16-2010
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 expirydate stlcno lastname status ....

file2 is having data i want the file1 shud populate with the data in file2 apprpraitely or just sort the file2 sames as file1...

i am very much new to shell scripting please provide an example with code.....awaiting reply
# 2  
Old 08-16-2010
Code:
$
$
$ cat f0
c3,c1,c2,c4
$
$
$ cat f1
c1,c2,c3,c4
a,b,c,d
e,f,g,h
i,j,k,l
m,n,o,p
q,r,s,t
$
$
$
$ perl -ne 'chomp; close ARGV if eof;
            if ($ARGV eq "f0") {@x = split/,/}
            elsif ($.==1) {@h = split/,/; print join(",",@x),"\n"}
            else {@d = split/,/; foreach $i(0..$#d) {$y{$h[$i]} = $d[$i]}
                  foreach $i(0..$#x) {push @p, $y{$x[$i]}}
                  print join(",",@p),"\n"; @p = ()}
           ' f0 f1
c3,c1,c2,c4
c,a,b,d
g,e,f,h
k,i,j,l
o,m,n,p
s,q,r,t
$
$

tyler_durden
# 3  
Old 08-17-2010
Hi durden_tyler,

Thanks Very Much but i have to use unix script for this ....could help me
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to sort a column in excel/csv file?

I have to sort the 4th column of an excel/csv file. I tried the following command sort -u --field-separator=, --numeric-sort -k 2 -n dinesh.csv > test.csv But, it's not working. Moreover, I have to do the same for more than 30 excel/csv file. So please help me to do the same. (6 Replies)
Discussion started by: dineshkumarsrk
6 Replies

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

Sort Excel File

Hi, I am new to scripting. I have a requirement 1.convert excel 2007 format to excel 2003 fromat 2.sort the excel file -( all columns in descending order). This needs to be done progarmmatically. Please let me know what would be the possible steps that I would need to take inorder to... (2 Replies)
Discussion started by: eva13
2 Replies

6. Shell Programming and Scripting

csv file to excel issue

Hi, I am trying to attach and email a csv file in the form of an excel sheet. And I have been successful in doing this. But after some days I realised that some fields in the csv file are also having commas because of which this field is getting splitted in columns in the excel sheet. ... (5 Replies)
Discussion started by: girish1428
5 Replies

7. UNIX for Dummies Questions & Answers

Excel File to CSV

Hi All, I have to convert the excel file which will be placed in the Unix box to a CSV file using a shell script. Please Advise. Thanks & Regards, Kumar66 (1 Reply)
Discussion started by: kumar66
1 Replies

8. Shell Programming and Scripting

Perl script to sort an Excel file

Hello! I need to sort a file that is partly in English partly in Bulgarian. The original file is an Excel file but I converted it to a tab-delimited text file. The encoding of the tab delimited file is UTF-8. To sort the text, the script should test every line of the text file to see if... (9 Replies)
Discussion started by: degoor
9 Replies

9. Shell Programming and Scripting

text file to excel or csv

Hi, I have a text file like ---------------------- aaa|bbb|ccc|ddd|eee fff|gggg|hhhhhh|kkkk -------------------- I have a script which will transfer(thourgh FTP) this text file to windows system. But I want to covert it into excel or CSF then upload into windows system.. thanks (9 Replies)
Discussion started by: srikanthus2002
9 Replies
Login or Register to Ask a Question