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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:03:28+00:00 2026-06-11T15:03:28+00:00

KSH HP-SOL-Lin Cannot use xAWK I have several strings that are quite long and

  • 0

KSH
HP-SOL-Lin
Cannot use xAWK

I have several strings that are quite long and i want to break them down into smaller substrings.

What I have

String = "word1 word2 word3 word4 .....wordx"

What I want

String1="word1 word2"
String2="word3 word4"
String3="word4 word5"
Stringx="wordx wordx+1"
etc.....

How Can i break this up to where if my string is longer than x words, break into smaller strings no longer than x? I have no idea how long each string will be. We can test for it, but it will not be consistent.

StrLen=`echo $string |wc -w`

Some strings are longer than 2000 words, so i cannot use a shell array as there is a max of 1024 fields.

ideas?

Here is what I have come up with based on comments below

FIELDS=`echo $String | wc -w`
((n=$FIELDS/2+1))
i=1

while [[ $i -le $n ]]; do
typeset STRING$i=`echo $String | cut -d" " -f$CUTSTART-$CUTEND`
do stuff

i=`expr $i+1`
CUTSTART=`expr $CUTSTART+1`
CUTEND=`expr $CUTEND+1`
done

Still seem to be having issues with the typeset peice.
Assumptions

i=1
CUTSTART=1
CUTEND=2
String=one two three

myserver> typeset STRING=`echo $String | cut -d" " -f$CUTSTART-$CUTEND`
myserver> echo $STRING
myserver> one two
myserver>
myserver> typeset STRING$i=`echo $String | cut -d" " -f$CUTSTART-$CUTEND`
myserver> echo $STRING1
myserver> one

what is this issue with $i messing up my echo|cut command?

  • 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-11T15:03:29+00:00Added an answer on June 11, 2026 at 3:03 pm

    Here’s a loop that uses read to extract two words at a time:

    # Take advantage of the fact that ksh doesn't execute
    # read in a subshell.
    i=1
    String="one two three four five six seven eight"
    while echo $String | read w1 w2 w3; do
        typeset "String$i=$w1 $w2"
        if [ -z $w3 ]; then
            break;
        fi
        String=$w3
        let i=i+1
    done
    echo $String1
    echo $String2
    echo $String3
    # etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a loop in my KornShell (ksh) script that I want to execute
I writing a ksh shell script and I have long comma separated string that
I have a script that needs to use associative arrays. Being new to ksh
I have a ksh script that returns a long list of values, newline separated,
I have a customized .profile that I use in ksh and below is a
So.. I use KSH on Solaris8 for quite long but this is the first
KSH - HP-SOL-Lin Needs to be POSIX I want to test if multiple conditions
the following script testssh.ksh proves that ssh have some problems when we try to
I have a script (KSH script to be precise) that downloads 3 files from
I have a KornShell (ksh) script that logins into SQL*Plus and executing a script.

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.