Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3499170
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:34:45+00:00 2026-05-18T12:34:45+00:00

Hi Need a shell script to parse through the csv file – Line by

  • 0

Hi Need a shell script to parse through the csv file – Line by line and then field by field ]

the file will look like this

X1,X2,X3,X4
Y1,Y2,Y3,Y4

I need to extract each of these X1,X2….

I wrote a script but it fails if the line exceeds one line..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:34:46+00:00Added an answer on May 18, 2026 at 12:34 pm

    Here’s how I would do it.

    First i set the IFS environment variable to tell read that “,” is the field separator.

    export IFS=","
    

    Given the file “input” containing the data you provided, I can use the following code:

    cat test | while read a b c d; do echo "$a:$b:$c:$d"; done
    

    To quickly recap what is going on above. cat test | reads the file and pipes it to while. while runs the code between do and done while read returns true. read reads a line from standard input and separates it into variables (“a”, “b”, “c” and “d”) according to the value of $IFS. Finally echo just displays the variables we read.

    Which gives me the following output

    X1:X2:X3:X4
    Y1:Y2:Y3:Y4
    

    BTW, the BASH manual is always good reading. You’ll learn something new every time you read it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to have a Shell script that will * Identify all the files [
I need to create a shell script to do this: ssh to another remote
I have shell script like - while read -r line; do echo $line done
I need some help from the shell-script gurus out there. I have a .txt
Basically I need to run the script with paths related to the shell script
I'm writing a shell script to do some web server configuration. I need to
I need a serviceable shell for MSYS. This is my current dilemma: The default
I'm need to create a Python shell script that refresh output every n seconds
The corrupt table entry is logged in the error file something like this... /usr/local/mysql/bin/mysqld:
I need to parse a large log file (flat file), which contains two column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.