Created
January 27, 2013 22:33
-
-
Save pklall/4651011 to your computer and use it in GitHub Desktop.
Bash script to reformat MSFT 2013 intern data to a cleaner csv format
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
#!/bin/bash | |
# Usage: ./interns.sh interns.txt | |
# loop over all lines of the file | |
while read line | |
do | |
# ignore blank lines | |
if [ "$line" == "" ] | |
then | |
continue | |
fi | |
# Try to extract start date | |
isdate=$(sed -n -e '/\w\+ [0-9]\+/p' <<< "$line") | |
if [ "$isdate" != "" ] | |
then | |
date=$isdate | |
continue | |
fi | |
# Extract line data | |
name=$(sed -n -e 's/\(\w\+\)\s*(.*/\1/p' <<< "$line") | |
data=$(sed -n -e 's/[^(]*(\(.*\))/\1/p' <<< "$line") | |
# Print csv data with prepended start date | |
printf "%s, %s, %s\n" "$name" "$date" "$data" | |
done < $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment