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 8006559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:33:03+00:00 2026-06-04T17:33:03+00:00

If I have a file like this: A:a B:b C:c I need to create

  • 0

If I have a file like this:

A:a
B:b
C:c

I need to create 2 arrays like

one=('A' 'B' 'C')
two=('a' 'b' 'c')

How can I do it in bash?

I’ve tried this:

declare -a one
declare -a two

while read line
do
    IFS=':' read -ra ADDR <<< $line
    echo ${ADDR[0]}
    echo ${ADDR[1]}
done < file.txt

Sorry I wrote from work and then I came home. Sorry again. The problem with this is that it’s printing

littlelion:Documents dierre$ sh prova.sh 
A a

B b

so it’s missing C c and I have no idea how to add an element to an array

  • 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-04T17:33:06+00:00Added an answer on June 4, 2026 at 5:33 pm

    Quotes fix everything:

    while read line
    do
        IFS=':' read -ra ADDR <<< "$line"
        echo ${ADDR[0]}
        echo ${ADDR[1]}
    done < file.txt
    

    Quoting the variable "$line" is what made the difference. If you’re not getting the line with “C:c”, it’s probably because your file is missing a final newline.

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

Sidebar

Related Questions

I have file with bitarray that looks like this: 10000000000000000000000000000000000000000000000000000000000000000000001000000 I need to make
I have a php file that returns a string like this [item1,item2,item3,item4] I need
I need to create excel file through code in iPhone i have two array
I have a Property File like this: frame.server.dev=mark.is.cool frame.server.test=chris.is.cool frame.server.qa=mitch.is.cool frame.server.prod=cory.is.cool I need to
i have a file that looks like this: sdfkhsdf,sdfgsg,sdfsdf,sdsdf sdfsdf,43534,sdfsdf,24234,sfddsf efsdf,234234,sdfsdf,234234,sadfsdf i need to
I have a file like this: [10/May/2012:00:00:03 +0000] [10/May/2012:00:00:03 +0000] [10/May/2012:00:00:03 +0000] [10/May/2012:00:00:03 +0000]
I have a file like this: This is a file with many words. Some
I have a file like this. rm a.txt mkdir foo cp a.doc docs I
i have a file like this: term1 term2 term3 term4 term2 term1 term5 term3
I have a file like this: This is a sentence. This is another sentence.

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.