Search code examples
bashcsvline

Line gestion csv bash


sorry if this issue has been covered before but I couldn't find the topic.

My csv.csv :

uid:titi      
20220310  
uid:toto  
20220410  
uid:tata  
20220805  
uid:tuti  
20220304  

What I want is that my new csv look like this:

newcsv.csv

titi;20220310   
toto;20220410    
tata;20220805  
tuti;20220304  

I tried with read but I don't manage to split the line by peer.

Thanks for your help.


Solution

  • Try this:

    cat csv.csv | sed 's/uid://g' | awk '{key=$0; getline; print key ";" $0;}'  | tr -d ' '
    

    The output as you prefer:

    titi;20220310
    toto;20220410
    tata;20220805
    tuti;20220304