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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:49:24+00:00 2026-05-23T14:49:24+00:00

I’m trying to transform a given line to an array, for example this line

  • 0

I’m trying to transform a given line to an array, for example this line :

My first\t \tHello world

to the following ksh/bash array:

[0]="My first"
[1]=""
[2]="Hello world"

My code:

TAB=`printf '\011'`

query()
{
    echo "$1"|awk -F"$TAB" '
        { 
            for(i = 0; i < NF; i++)
                QueryArray[i]=$i
        }';
}

line=`head -n 1 myFile`
typeset -a QueryArray;
query "$line"
echo "Array length: ${#QueryArray[*]}"
echo "- " ${QueryArray[0]}
echo "- " ${QueryArray[1]}
echo "- " ${QueryArray[2]}

but doesn’t work, any suggestions?

Thanks.

  • 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-23T14:49:24+00:00Added an answer on May 23, 2026 at 2:49 pm

    I have an older ksh that does not understand $'ANSI' strings, so:

    str2array () {
        typeset arrayname=$1
        typeset IFS=$2
        shift 2
        eval "set -A $arrayname \$*"
    }
    
    s="Hello        World"     # tabs entered literally with "Ctrl-V tab"
    str2array myarray " " "$s"     # another literal tab as 2nd parm
    typeset -i i=0
    while [[ $i -lt ${#myarray[@]} ]]; do
        printf "%d\t%s\n" $i "${myarray[$i]}"
        i=$(( i+1 ))
    done
    

    for bash:

    str2array () {
        local arrayname=$1
        local IFS=$2
        shift 2
        eval "$arrayname=( \$* )"
    }
    
    s=$'hello\t\tworld'
    str2array myarray $'\t' "$s"
    for (( i=0; i < ${#myarray[@]}; i++ )); do
        printf "%d\t%s\n" $i "${myarray[$i]}"
    done
    

    I’m getting the same result ar Arnaud’s comment to David: with “word\t\tword”, the middle field is being dropped. I don’t see that with a different delimiter such as colon.

    ksh

    Blank Interpretation
    After parameter and command substitution, the results of
    substitutions are scanned for the field separator characters
    (those found in IFS) and split into distinct arguments where
    such characters are found. Explicit null arguments ( “” ) or
    (”) are retained. Implicit null arguments (those resulting
    from parameters that have no values) are removed.

    bash

    Word Splitting
    …
    The shell treats each character of IFS as a delimiter, and splits the
    results of the other expansions into words on these characters. If IFS
    is unset, or its value is exactly <space><tab><newline>, the default,
    then sequences of <space>, <tab>, and <newline> at the beginning and
    end of the results of the previous expansions are ignored, and any
    sequence of IFS characters not at the beginning or end serves to
    delimit words. If IFS has a value other than the default, then
    sequences of the whitespace characters space and tab are ignored at the
    beginning and end of the word, as long as the whitespace character is
    in the value of IFS (an IFS whitespace character). Any character in
    IFS that is not IFS whitespace, along with any adjacent IFS whitespace
    characters, delimits a field. A sequence of IFS whitespace characters
    is also treated as a delimiter
    . If the value of IFS is null, no word
    splitting occurs.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.