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

Given a string like this: <a href=http://blah.com/foo/blah>This is the foo link</a> ... and a
So I have a cronjob which executes a PHP script like so: 0 0
Similar to this thread for C# , I need to split a string containing
I'm trying to parse a MYSQL slow query log from the command line. Upon
I wan't to write a script to get the source of a website which
I am using this function in Bash function parse_git_branch { git_status=$(git status 2> /dev/null)
We want to build a script that run every night (kills and restart a
Im trying to fix a Python script which takes the posts from a specific
I have a primarily Ajax-driven site, the content of which is populated by making
I have lots of home directories under /ifshome on Linux. I want to see

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.