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

  • SEARCH
  • Home
  • 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 8851425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:09:10+00:00 2026-06-14T13:09:10+00:00

I have while read $field1 $field2 $field3 $field4 do $trimmed=$field2 | sed ‘s/ *$//g’

  • 0

I have

while read $field1 $field2 $field3 $field4
do
  $trimmed=$field2 | sed 's/ *$//g'
  echo "$trimmed","$field3" >> new.csv
done < "$FEEDS"/"$DLFILE"

Now the problem is with read I can’t make it split fields csv style, can I? See the input csv format below.

I need to get columns 3 and 4 out, stripping the padding from col 2, and I don’t need the quotes.

Csv format with col numbers:
12 24(“)25(,)26(“)/27(Field2values) 42(“)/43(,)/44(Field3 decimal values)
“Field1_constant_value”,”Field2values “,Field3,Field4

Field1 is constant and irrelevant. Data is quoted, goes from 2-23 inside the quotes.
Field2 fixed with from cols 27-41 inside quotes, with the data at the left and padded by spaces on the right.
Field3 is a decimal number with 1,2, or 3 digits before the decimal and 2 after, no padding. Starts at col 74.
Field4 is a date and I don’t much care about it right now.

  • 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-06-14T13:09:11+00:00Added an answer on June 14, 2026 at 1:09 pm

    Yes, you can use read; all you’ve got to do is reset the environment variable IFS — Internal Field Separator –, so that it won’t split lines by its current value (default to whitespace), but by your own delimiter.

    Considering an input file “a.csv”, with the given contents:

    1,2,3,4

    2,3,4,5

    6,3,2,1

    You can do this:

    IFS=','
    while read f1 f2 f3 f4; do
        echo "fields[$f1 $f2 $f3 $f4]"
    done < a.csv
    

    And the output is:

    fields[1 2 3 4]

    fields[2 3 4 5]

    fields[6 3 2 1]

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

Sidebar

Related Questions

Say you have a simple loop while read line do printf ${line#*//}\n done <
I have part of my script that goes like this: while read line do
I've been doing web development for a while and have yet to read a
I have some codes read the query results from sqlite: while (sqlite3_step(statement) == SQLITE_ROW)
I have a while loop that loops through 3 results and echo's these out
The while loop I have while reading in from a file doesn't break. I'm
I have problem while loading data into html select when users press or click
I have a while loop that goes while a BuffedReader still has data, what
I have problem while using jquery maskedinput with asp.net textbox. I have a check
hi i have a while loop: var i = 0; while(i < 20) {

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.