')}.swal-popup-animation{opacity:0;visibility:hidden}@media only screen and (max-width:480px){#popup-wrapper-ajax-auth{left:0;margin-left:0}.inner-form-ajax-forms{width:100%;float:left}.ajax-auth h4:after,.ajax-auth h4:before{width:80px}}.bellows.bellows-main{--bellows-indent:3px;width:318px;--bellows-item-padding-v:1px;--bellows-item-padding-h:5px;--bellows-sub-item-padding-v:2px;--bellows-sub-item-padding-h:15px}.bellows.bellows-main,.bellows.bellows-main .bellows-menu-item,.bellows.bellows-main .bellows-menu-item .bellows-target{font-family:"Segoe UI",Arial,sans-serif}.bellows.bellows-main .bellows-nav .bellows-item-level-0>.bellows-target{color:#000}.bellows.bellows-main .bellows-nav .bellows-item-level-0.bellows-current-menu-ancestor>.bellows-target{color:#000}.bellows.bellows-main .bellows-nav .bellows-item-level-0>.bellows-target{font-size:16px}.bellows.bellows-main .bellows-nav .bellows-submenu .bellows-current-menu-item>.bellows-target{background-color:#44ba54;color:#000}.bellows.bellows-main .bellows-nav .bellows-submenu .bellows-target{color:#000}.bellows.bellows-main .bellows-nav .bellows-submenu .bellows-menu-item>.bellows-target{font-size:15.5px}@media screen{.ajax-auth{max-width:320px}#popup-wrapper-ajax-auth{background-color:#fff;color:#333;border-radius:15px}#wrapper-forgot_password,#wrapper-login,#wrapper-register{border-radius:15px}.ajax-auth a.text-link,.ajax-auth h4{color:#b2b0b0}.ajax-auth h4:after{background-color:#b2b0b0}.ajax-auth h4:before{background-color:#b2b0b0}.login_overlay{background-color:rgba(0,0,0,.5)}.ajax-auth h3 a{color:#3fb950}.ajax-auth .submit_button{background:-moz-linear-gradient(top,#3fb950,#35af46);background:linear-gradient(to bottom,#3fb950,#35af46);border-color:#219b32;box-shadow:0 1px 0 #5dd76e inset;background-color:#3fb950;border-radius:3px;height:40px;line-height:38px}.ajax-auth input[type=password],.ajax-auth input[type=text]{border-radius:3px;height:40px!important;line-height:40px!important;border-color:#9a9a9a;color:#333!important;background-color:#f9f9f9!important}.swal-input-icons i{height:40px;line-height:38px}.ajax-auth h3{color:#333}#popup-wrapper-ajax-auth{max-width:340px;margin-left:-170px}.inner-form-ajax-forms{width:100%;float:none}@media only screen and (max-width:480px){#popup-wrapper-ajax-auth{left:0;margin-left:0}}@media only screen and (min-width:481px) and (max-width:960px){#popup-wrapper-ajax-auth{left:50%}}}.about-author{font-size:16px;font-weight:600;color:#000;margin-bottom:-10px!important}.author_links{font-size:15px;font-weight:600;margin-right:30px!important}.author-avatar{border-radius:50%;margin-right:125px!important;margin-top:-59px!important}.author_bio_section{display:flex!important;flex-direction:column!important;flex-wrap:wrap;justify-content:flex-start;align-items:flex-start;align-content:flex-start}.pum-form--style-default input[type=email]{background-color:#f8f7f7;margin-bottom:5px;font-size:14px;width:300px;border-radius:10px;height:40px}.pum-form--style-default button{border-radius:10px;font-size:14px;height:40px}.ast-page-builder-template.single .post-navigation{width:1200px!important}@media only screen and (max-width:1500px){.ast-page-builder-template.single .post-navigation{width:100%!important}}@media only screen and (max-width:500px){@media only screen and (max-width:921px){.ast-left-sidebar.ast-page-builder-template #secondary{display:none}}@media only screen and (max-width:921px){.bellows .bellows-nav,.bellows .bellows-nav .bellows-menu-item,.bellows .bellows-nav .bellows-submenu{margin-right:-20px;padding:5px 0}}.ast-mobile-popup-drawer .ast-mobile-popup-inner{overflow-y:hidden;overflow-x:hidden}.gutena-tabs-block>.gutena-tabs-tab{z-index:9;background:#eee;width:98%;box-shadow:.2px .2px .2px .2px #eee;padding:0 40px;top:44px!important;margin-left:0!important}.gutena-tabs-block>.gutena-tabs-tab>.gutena-tab-title{background:#eee;padding:10px;font-size:14px;font-weight:700}.gutena-tabs-block>.gutena-tabs-tab>.gutena-tab-title.active{background:#eee;border-bottom:solid 3.5px #3fb950;border-radius:2px;color:#3fb950}@media only screen and (max-width:500px){.gutena-tabs-block>.gutena-tabs-tab{position:relative!important;width:90%;box-shadow:.2px .2px .2px .2px #eee;padding:0 40px;top:0!important}}.ast-page-builder-template .comments-area{display:none!important}.comments-area{display:none}.ast-left-sidebar.ast-page-builder-template #secondary{width:318px;height:auto!important}.ast-below-header-bar{margin-bottom:-10px}#secondary{width:318px;margin-left:0;margin-top:-20px;background:#eee;border:none!important;padding-bottom:100vh;margin-bottom:0}@media (min-width:922px){#secondary{padding-left:0!important;padding-right:0!important;margin-left:-25px!important}}.sidebar-main{margin-left:25px;margin-top:-10px}.bellows.bellows-main{margin-top:30px;position:absolute}.bellows.bellows-main .bellows-nav .bellows-item-level-0>.bellows-target{font-weight:600;font-size:17px;margin-top:20px;padding-top:1px!important;padding-bottom:1px!important}.bellows .bellows-nav .bellows-active>.bellows-submenu{padding-top:20px;padding-bottom:10px}.bellows .bellows-nav .bellows-target>.bellows-target-text{margin-top:-3px;margin-bottom:-3px}.bellows-nav{position:relative;overflow-y:scroll;overflow-x:hidden;height:80vh!important;max-width:100%;direction:ltr}@media only screen and (max-width:2560px){.bellows-nav{height:98.8vh!important}}@media only screen and (max-width:1920px){.bellows-nav{height:97.5vh!important}}::-webkit-scrollbar{width:11px}::-webkit-scrollbar-track{background:#eee}::-webkit-scrollbar-thumb{background:#62615c}::-webkit-scrollbar-thumb:hover{background:#555}.ast-left-sidebar.ast-page-builder-template #secondary{padding-left:0;padding-right:0;margin-top:-20px;margin-bottom:0;margin-right:15px;border-right:none;background:#eee}.ast-header-search .ast-search-menu-icon.slide-search .search-form{border-radius:15px!important;height:35px!important}.entry-content{padding-left:10px;padding-top:20px}.ast-left-sidebar #primary{border-left:none}.single .post-navigation{border-top:none}.nav-next p{margin-top:10px;margin-bottom:10px;font-weight:400!important;text-align:right}.nav-previous p{margin-top:10px;margin-bottom:10px;font-weight:400!important;text-align:left}.single .nav-links .nav-previous,.single .nav-links .nav-next{font-weight:600!important}.wpulike-heart .wp_ulike_general_class{box-shadow:0 0 0 3px #3fb950 inset;border-radius:15px}.wpulike-heart .wp_ulike_put_text{color:#3fb950}.wpulike-heart .count-box{color:#3fb950!important}.wpulike{display:inline-flex!important;align-items:center;flex-wrap:wrap;align-content:center;justify-content:space-around;width:1200px!important}@media only screen and (max-width:1500px){.wpulike{display:flex!important;align-items:center;flex-wrap:wrap;align-content:center;justify-content:space-around;width:100%!important}}html{height:100%!important}body{height:100%!important}input.search-field{height:45px;width:350px;border:none;border-radius:0}input.search-submit{color:#fff;background:#4b4f58;height:46px!important;border-radius:0;border-right:solid 1px #3fb950;margin-right:0!important;margin-left:-4px!important}@media only screen and (max-width:440px){input.search-field{width:155px!important}}@media only screen and (max-width:540px){input.search-field{width:270px!important}}@media only screen and (max-width:420px){input.search-field{width:148px!important}}@media only screen and (max-width:400px){.ast-mobile-popup-drawer .ast-mobile-popup-header{margin-top:10px}@media only screen and (max-width:921px){.bellows .bellows-nav,.bellows .bellows-nav .bellows-menu-item,.bellows .bellows-nav .bellows-submenu{margin-right:0!important;padding-top:2px!important;padding-bottom:5px;!important;padding-left:5px!important;padding-right:1px!important}}@media only screen and (max-width:2556px){.bellows-nav{height:98vh!important}}.gutena-tabs-block-bd37a0-22{--gutena--tabs-tab-spacing:0px;--gutena--tabs-tab-after-gap:15px;--gutena--tabs-tab-font-size:16px;--gutena--tabs-tab-padding:8px 20px;--gutena--tabs-tab-text-color:#272a41;--gutena--tabs-tab-icon-spacing:5;--gutena--tabs-tab-container-padding:20px}.wp-container-1.wp-container-1,.wp-container-2.wp-container-2,.wp-container-3.wp-container-3,.wp-container-4.wp-container-4,.wp-container-5.wp-container-5{justify-content:flex-end;align-items:center}.ast-desktop .menu-item-7815 .astra-mm-icon-label.icon-item-7815{display:inline-block;vertical-align:middle;line-height:0;margin:1px}.ast-desktop .menu-item-7815 .astra-mm-icon-label.icon-item-7815 svg{width:23px;height:23px;color:var(--ast-global-color-4);fill:var(--ast-global-color-4)}}}
Extract Data From a CSV File | Data Transformation - Datanerds.io
Skip to content
Extract Data From a CSV File and Transform it Into a Desired Format
Read
Discuss
You can extract data from a CSV file and transform it into a desired format using the following steps in bash:
Read the CSV file line by line using a loop and the read command.
Parse the values in each line using the IFS (Internal Field Separator) variable.
Store the values in variables.
Use the values in variables to build the desired format.
Echo the result to the console or write it to a file.
Here’s an example of extracting data from a CSV file and transforming it into a tab-separated format:
#!/bin/bash# Specify the input fileinput_file="data.csv"# Read the file line by linewhileIFS=',' read -r col1 col2 col3do# Transform the values into tab-separated formatresult="$col1\t$col2\t$col3"# Echo the resultecho"$result"done< "$input_file"