cat data.csv | sed s/","/" "/g | xargs -L 1 | split.sh
Created
January 11, 2022 23:37
-
-
Save thomaslorentsen/7b998bc6309f94ab45117ff0df3a4739 to your computer and use it in GitHub Desktop.
Split strings in bash
This file contains hidden or 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
id | date | |
---|---|---|
60666 | 13/01/2022 |
This file contains hidden or 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 | |
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