How Do You Split a Line Using Delimiter in Unix?
Contents How Do You Split a String with Delimiter in Unix? Bash Script #! /Bin/Bash. #Example for Bash Split String Without $Ifs. Read -P “Enter Any String...
Contents
How do you split a string with delimiter in Unix?
Bash Script
- #!/bin/bash.
- #Example for bash split string without $IFS.
- read -p “Enter any string separated by colon(:) ” str #reading string value.
- readarray -d : -t strarr <<<“$str” #split a string based on the delimiter ‘:’
- printf “n”
- #Print each value of Array with the help of loop.
- for (( n=0; n < ${#strarr[*]}; n++ ))
Must Read
How do you split a string with delimiter?
Example of Pipe Delimited String
- public class SplitStringExample5.
- {
- public static void main(String args[])
- {
- //defining a String object.
- String s = “Life|is|your|creation”;
- //split string delimited by comma.
- String[] stringarray = s.split(“|”); //we can use dot, whitespace, any character.