Skip to content

Instantly share code, notes, and snippets.

@pklall
Created January 27, 2013 22:33
Show Gist options
  • Save pklall/4651011 to your computer and use it in GitHub Desktop.
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
#!/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