1

This is my input file

0164318,001449,001452,001922  
0164318,001456,001457,001922  
0842179,002115,002118,001485  
0846354,001512,001513,001590  
0841422,001221,001224,001860  
0841422,001227,001228,001860

I want my result as

0164318,001449,001457,001922  
0842179,002115,002118,001485  
0846354,001512,001513,001590  
0841422,001221,001228,001860 

group by using col1 and to find min(col2) and max(col3)
through shell script.

ilkkachu
  • 138,973
Aditya
  • 29
  • 1
  • 6
  • 3
    From U&L Help: "Have you thoroughly searched for an answer before asking your question? Sharing your research helps everyone. Tell us what you found and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself" – pLumo Jan 17 '19 at 10:01
  • In other words: What did you try? People are not here to do your work but to help you do your work. – pLumo Jan 17 '19 at 10:02
  • I am trying to create a validation script, where i am doing same operation in sql table, well I am new to shell scripting so that I am asking whether its possible in shell or not? – Aditya Jan 17 '19 at 10:06
  • Please [edit] your question and clarify what you are trying to do. What if the min value for column 2 associated with 0164318 in column 1, and the max value for column 3 are on different lines? Also, does it need to be a shell script? The shell is a very bad tool for text processing. – terdon Jan 17 '19 at 10:14
  • $ awk -F, '{if (a[$1] < $3)a[$1]=$3;}END{for(i in a){print i,a[i];}}' OFS=, file ------ Through this command I am able to find the max in col3 for every group of col1 , – Aditya Jan 17 '19 at 10:31
  • Please, edit your question instead of adding information in comments. 2) What about column 4? Does equal values for column 1 always mean that values for column 4 are equal, too?
  • – fra-san Jan 17 '19 at 10:35
  • no need to worry about column 4 .. in this case col4 value is unique for each value of col1 – Aditya Jan 17 '19 at 10:38
  • It is still really unclear if you want to 1) issue SQL commands against your file using a tool available in the shell and able to behave similarly to an RDBMS (this will lead, for instance, to the csvkit based answers you have) OR 2) manipulate your file using something that is not SQL, nor an RDBMS (e.g. shell constructs, awk, ...) in a way equivalent to the SQL command you provided. – fra-san Jan 17 '19 at 13:53
  • @Aditya, mm, why the edit to remove the example data? The question was a lot more clear and useful with it. – ilkkachu Mar 13 '19 at 18:18