Created
January 29, 2016 16:56
-
-
Save NTerpo/abd9e07bf1a3db52141a to your computer and use it in GitHub Desktop.
some data cleaning shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change extension for txt files to csv files | |
$ for f in *.txt | |
do | |
[ -f "$f" ] && mv "$f" "${f%txt}csv" | |
done | |
# Remove first line every csv files | |
$ for f in *.csv | |
do | |
[ -f "$f" ] && awk '{if (NR==1 || NR==2) next};1' "$f" >> "clean_$f" | |
done | |
# Add a column with name of file for each csv file | |
$ for f in *.csv | |
do | |
[ -f "$f" ] && awk -F" " 'BEGIN { OFS = " " } ; {if (NR==1) next} ; { $6="'$f'" OFS $6; print}' "$f" >> "new_$f" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment