Skip to content

Instantly share code, notes, and snippets.

@thomaslorentsen
Created January 11, 2022 23:37
Show Gist options
  • Save thomaslorentsen/7b998bc6309f94ab45117ff0df3a4739 to your computer and use it in GitHub Desktop.
Save thomaslorentsen/7b998bc6309f94ab45117ff0df3a4739 to your computer and use it in GitHub Desktop.
Split strings in bash

Example Usage

cat data.csv | sed s/","/" "/g | xargs -L 1 | split.sh
id date
60666 13/01/2022
#!/bin/bash
if [ "$1" == "id" ]; then
# skip line heading
exit
fi
# Split the date string
IFS=/ read day month year <<< $2
# Format into sql date
NEWDATE=$year-$month-$day
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment