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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:08:30+00:00 2026-06-06T06:08:30+00:00

Can split(string, array, separator) in awk use sequence of whitespaces as the separator (or

  • 0

Can split(string, array, separator) in awk use sequence of whitespaces as the separator (or more generally any regexp as the separator)?

Obviously, one could use the internal autosplit (that runs on each line of the input with value of FS variable as the separator) and with simple for and $0 magic do the trick. However, I was just wondering if there’s a more straightforward way using the splititself.

  • 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-06T06:08:32+00:00Added an answer on June 6, 2026 at 6:08 am

    The GNU Awk User’s Guide states:

    split(string, array, fieldsep)
    

    This divides string into pieces separated by fieldsep, and stores the
    pieces in array. The first piece is stored in array[1], the second
    piece in array[2], and so forth. The string value of the third
    argument, fieldsep, is a regexp describing where to split string (much
    as FS can be a regexp describing where to split input records). If
    the fieldsep is omitted, the value of FS is used. split returns the
    number of elements created. The split function, then, splits strings
    into pieces in a manner similar to the way input lines are split into
    fields

    Here is a short (somewhat silly) example that uses a simple regular expression ".s " that will match any single character followed by a lower-case s and a space. The result of the split is put into array a. Note that the parts that match are not placed into the array.

    BEGIN { 
      s = "this isn't a string yes isodore?"
      count = split(s, a, ".s ")
      printf("number of splits: %d\n", count)
    
      print "Contents of array:"
      for (i = 1; i <= count; i++) 
        printf "a[%d]: %s\n", i, a[i]
    }
    

    The output:

    $ awk -f so.awk
    
    number of splits: 3
    Contents of array:
    a[1]: th
    a[2]: isn't a string y
    a[3]: isodore?
    

    The article Advanced Awk for Sysadmins show an example of parsing a line using split(). This page contains an example of using a regular expression to split data into
    an array.

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

Sidebar

Related Questions

How can I split a string into an array of strings based on a
Given a string such as: 23,234,456 first second third How can I split string
How can I split a String by Unicode range in Ruby. I wanted to
How can I split a string such as Mar10 into Mar and 10 in
How can I convert my list of strings: List<string> appliedFilters = filterString.Split(',').Select(n => n).ToList();
Do MySQL have any function by which I can split data of a column
how can I split this barcode by group separator with Progress? I've tried chr(29)
I can use JavaScript's split to put a comma-separated list of items in an
Currently I'm using something like : String[]lines = textContent.split(System.getProperty(line.separator)); for(String tmpLine : lines){ //do
I want to split a string that can look like this: word1;word2;word3,word4,word5,word6.word7. etc. The

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.