split() { local string="$1" local delimiter="$2" if [ -n "$string" ]; then local part while read -d "$delimiter" part; do echo $part done <<< "$string" echo $part fi } 例如,命令 $ split 'a;b;c' ';' 产量 a b c 例如,此输出可以通过管道传输到其他命令。例子: ...
在这个函数的底部,你会发现一个函数,它可以将string转换为一个array,语法如下:
在这个函数的底部,你会发现一个函数,它可以将string转换为一个array,语法如下:
Read line by line in Bash script。 (${IN//;/ }):以;分隔的字符串 IN 转数组 How do I split a string on a delimiter in Bash? 示例如下: IN="bla@some.com;john@home.com" arrIN=(${IN//;/ }) echo ${arrIN[1]} 分隔字符串为数组 ...
这是cut,awk和其他工具的替代品。示例函数:split() { # Usage: split "string" "delimiter" IFS=$'\n' read -d "" -ra arr <<< "${1//$2/$'\n'}" printf '%s\n' "${arr[@]}" }示例用法:$ split "apples,oranges,pears,grapes" "," apples oranges pears grapes $ split "1, 2, ...
In this example, the last element of the string is extracted using the IFS variable, which is set to a colon character ":". Splitting the string into words tells the shell to use a : as the delimiter. Without Using the IFS variable Use space as a delimiter to split the string in ba...
column 格式化输出文本,按照指定字符控制输出多列(有点和awk某些用法类似) colrm 列删除工具 join 通过相同字段来连接文件的行 od 以八进制或者其他格式转储文件内容(常用于查看二进制文件) hexdump 以ascii,十进制,16进制,八进制显示文本内容(常用于查看二进制文件) cp 复制文件或目录(文件) mv 移动或重命名文件 ...
Split a string on a delimiterCAVEAT: Requires bash 4+This is an alternative to cut, awk and other tools.Example Function:split() { # Usage: split "string" "delimiter" IFS=$'\n' read -d "" -ra arr <<< "${1//$2/$'\n'}" printf '%s\n' "${arr[@]}" }...
awk substr example Find command in linux Remove Newline from String in Bash Replace Character in String in Bash Generate Random String in Bash Run String as Command in Bash Bash Split String and Get Last Element Remove Double Quotes from String in Bash Bash Remove Special Characters from String...
${variable/ pattern/ string}${variable// pattern/ string} The longest match to pattern in variable is replaced by string. In the first form, only the first match is replaced. In the second form, all matches are replaced. If the pattern begins with a #, it must match at the start ...