Skip to content

Instantly share code, notes, and snippets.

@NTerpo
Created January 29, 2016 16:56
Show Gist options
  • Save NTerpo/abd9e07bf1a3db52141a to your computer and use it in GitHub Desktop.
Save NTerpo/abd9e07bf1a3db52141a to your computer and use it in GitHub Desktop.
some data cleaning shell
# 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