Skip to content

Instantly share code, notes, and snippets.

@snambi
Last active June 26, 2023 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snambi/1ba1ec29e251257946a81a4a33347068 to your computer and use it in GitHub Desktop.
Save snambi/1ba1ec29e251257946a81a4a33347068 to your computer and use it in GitHub Desktop.
How to extract different fields from a CSV file and print in a different format

awk is better than cut

How to extract different fields from a CSV file and print in a different format

Input file in CSV format

Sample input file

837998483934.ecr.us-west-2.amazonaws.com,consoleapi,1.0.0-fg47d32
837998483934.ecr.us-west-2.amazonaws.com,consoleapi,1.0.0-fg47d32
837998483934.ecr.us-west-2.amazonaws.com,consoleapi,1.0.0-fg47d32

Extract columns from the input file using AWK

awk -F, '{ print $1 "/" $2 ":"$3 }' input.csv 
837998483934.ecr.us-west-2.amazonaws.com/consoleapi:1.0.0-fg47d32
837998483934.ecr.us-west-2.amazonaws.com/consoleapi:1.0.0-fg47d32
837998483934.ecr.us-west-2.amazonaws.com/consoleapi:1.0.0-fg47d32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment