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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:02:53+00:00 2026-06-07T11:02:53+00:00

I have some comma separated strings and want to split them using cut command

  • 0

I have some comma separated strings and want to split them using cut command in bash:

This, is a, sample input.
This, is, another string, which could, appear, in my text, file.

I also want to print all the substrings in the output.
The desired output of the first string is:

This
is a
sample input.

and this is the desired output of the second string:

This
is
another string
which could
appear
in my text
file.

but since the number of commas(substrings) is not fixed in all of the strings, I don’t know how to tell the cut command to show all the substrings. (for example there 2 commas in the first string and 6 in the second). Is there any way to do this in bash (with cut or other commands)?

I have to add that although my examples in this post are in English, My actual strings are in Arabic language. I mean the command which I want to use, have to be able to work with Unicode characters.

  • 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-07T11:02:54+00:00Added an answer on June 7, 2026 at 11:02 am

    Just because you wanted cut:

    line='This, is a, sample input.'
    for i in $(seq 1 $(echo "$line," | tr -dc ',' | wc -c)); do
      echo $line | cut -d, -f$i; 
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A string contains some words separated by comma or space. Using PHP, I want
I have some input that looks like the following: A,B,C,"D12121",E,F,G,H,"I9,I8",J,K The comma-separated values can
I have a string ($c) that contains a comma-separated list of settings. Some settings
I have a table that contains a field of comma separated strings: ID |
I have a string comma separated list of some data. I have another list
I have some jquery code that is doing an ajax lookup and returning comma
I have some arbitrary pixel data that I want to save as a PNG.
I have string like this: command . / * or any other char like
I'm practicing some XSL and using this XML document as a simple example: <?xml
I have an array, some elements are single string, final element is comma seperated

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.