How Do You Split a Line Using Delimiter in Unix?
Contents

How do you split a string with delimiter in Unix?

Bash Script

  1. #!/bin/bash.
  2. #Example for bash split string without $IFS.
  3. read -p “Enter any string separated by colon(:) ” str #reading string value.
  4. readarray -d : -t strarr <<<“$str” #split a string based on the delimiter ‘:’
  5. printf “n”
  6. #Print each value of Array with the help of loop.
  7. for (( n=0; n < ${#strarr[*]}; n++ ))

How do you split a string with delimiter?

Example of Pipe Delimited String

  1. public class SplitStringExample5.
  2. {
  3. public static void main(String args[])
  4. {
  5. //defining a String object.
  6. String s = “Life|is|your|creation”;
  7. //split string delimited by comma.
  8. String[] stringarray = s.split(“|”); //we can use dot, whitespace, any character.
James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest