Sort and list values from CSV


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort and list values from CSV
# 8  
Old 11-05-2013
How did you try ? which is you bash ?
# 9  
Old 11-05-2013
Hi Askshay ,

Below is my code:

Code:
#!/bin/sh
#
SortOutput $OutputCSV $abc

function SortOutput
{
 awk -F, '$6 < 60 {exit}1' <(sort -t, -nk3,3 $1)  >>$2
}

# 10  
Old 11-05-2013
Quote:
Originally Posted by Nevergivup
Hi Askshay ,

Below is my code:

Code:
#!/bin/sh
#
SortOutput $OutputCSV $abc

function SortOutput
{
 awk -F, '$6 < 60 {exit}1' <(sort -t, -nk3,3 $1)  >>$2
}

function should be called after defining it
Code:
Code:
#!/bin/sh


function SortOutput()
{
 awk -F, '$6 < 60 {exit}1' <(sort -t, -nk3,3 $1)  >>$2
}
SortOutput $OutputCSV $abc

() was missing
# 11  
Old 11-06-2013
a) your sample did not have 6 fields, so don't expect anything to be printed with above proposal.
b) SHOULD your input have 6 fields or more, and $6 being the relevant one, you should also make it the sort key: -k6,6
# 12  
Old 02-17-2014
Thanks for your help on this. Now i have a new requirement as mentioned below:

I have a CSV with below values

Code:
name,city,2,country
name,city,15,country
abc,wq,10,afdfd,
qeqe,ewqre,1,wqew
abd, we,2,qwqe

I need to sort them in ascending order based on the value of column 3 and then , pick the rows with values less than 10 and be able to display the columns in that row. Also if the column 3 values are same , I need to print only one row:

for eg:
Only one of the row needs to printed.
Code:
name,city,2,country 
abd, we,2,qwqe

Moderator's Comments:
Mod Comment Please mark code, sample input, and sample output with CODE tags; not your entire message.

Last edited by Don Cragun; 02-17-2014 at 11:56 PM.. Reason: Reposition and add CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

2. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

3. Shell Programming and Scripting

List unique values and count instances in .csv file

I need to take the second column of a .csv file and count the number of instances of each unique value in that same second column. I'd like the output to be value,count sorted by most instances. Thanks for any guidance! Data example: 317476,317756,0 816063,318861,0 313123,319091,0... (4 Replies)
Discussion started by: batcho
4 Replies

4. Shell Programming and Scripting

Sort csv file

Hello, I am facing the following problem: I have a file in csv format. So several records where data fields are separated by comma ',' The lenght of the fields is variable, as well as the number of fields per record. But there are at least 7 fields per record. I need to sort the file based... (1 Reply)
Discussion started by: BSF
1 Replies

5. Shell Programming and Scripting

return a list of unique values of a column from csv format file

Hi all, I have a huge csv file with the following format of data, Num SNPs, 549997 Total SNPs,555352 Num Samples, 157 SNP, SampleID, Allele1, Allele2 A001,AB1,A,A A002,AB1,A,A A003,AB1,A,A ... ... ... I would like to write out a list of unique SNP (column 1). Could you... (3 Replies)
Discussion started by: phoeberunner
3 Replies

6. Shell Programming and Scripting

sort the csv file

hello , the content of a csv file is looking like this... vah1 , imk4 , LDAP Secure. vah1 , fmk1 , Not able to SSH vah1 , fk1 ,Not able to SSH vah1 , imk1 , LDAP Secure. vah1 , imk3 , Un-Secured vah1 , fmk1 , LDAP Secure. vah1 , fk1 , LDAP Secure. vah1 , fmk1 , LDAP Secure. vah1 ,... (2 Replies)
Discussion started by: nagendramv
2 Replies

7. Shell Programming and Scripting

Need to compare two csv files values and write into another csv file

Hi all, Am new to scripting. So i just need your ideas to help me out. Here goes my requirement. I have two csv files 1.csv 2.csv abc,1.24 abc,1 def,2.13 def,1 I need to compare the first column of 1.csv with 2.csv and if matches then need to compare... (2 Replies)
Discussion started by: chinnahyd
2 Replies
Login or Register to Ask a Question