Bash Script for Extracting Rows from CSV Files and Combine them by Column: An Example

@Runmin ZHAO  April 10, 2019
#!/bin/bash

for i in 0 15 30 45 60 75
do
    dir=Pedersen_$i
    cd $dir
    pvpython ../Crate.py
    for j in 4 5 6 7 8
    do    
        tail -n 1 file_${j}.csv >> ${dir}.csv #Extract the last line
    done
    mv ${dir}.csv ..
    cd ..
    awk -F ',' '{print $2}' ${dir}.csv > ${dir}awk.csv #paste the second columns. The splitter is comma

done

paste -d ',' *awk.csv > buoyant.csv

Add a New Comment