Last active
February 13, 2023 03:46
-
-
Save tecmaverick/7b414380771c02c7c069512de5a86f0f to your computer and use it in GitHub Desktop.
Insert Header to CSV AWK and Bash version
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
# abc.csv contents | |
# Alpha, USA, 12 | |
# Beta, USA, 13 | |
# abc.csv contents after adding header | |
# Name, Country, Age | |
# Alpha, USA, 12 | |
# Beta, USA, 13 | |
#Using streams - Solution1 | |
value=$(<abc.csv); echo "Name,Country,Age">abc.csv; echo "$value">>abc.csv | |
#Using streams - Solution2 | |
echo -e "Name,Country,Age\n$(cat abc.csv)">abc.csv | |
#Using AWK | |
a=$( awk -F, 'NR==1 {print "Name","Country","Age"}{print $1,$2,$3}' abc.csv | column -t);echo "$a">abc.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment