공부
[sh] csv string count
승가비
2023. 3. 16. 00:45
728x90
#!/bin/bash
input=$1
output=$2
rm $output
n=0
while read line; do
comma="${line//[^,]}"
cnt="${#comma}"
echo "Line No. ${n} : ${cnt}" >> $output
n=$((n+1))
done < ${input}
var="text,text,text,text"
res="${var//[^,]}"
echo "$res"
echo "${#res}"
,,,
3
https://stackoverflow.com/questions/16679369/count-occurrences-of-a-char-in-a-string-using-bash
Count occurrences of a char in a string using Bash
I need to count the number of occurrences of a char in a string using Bash. In the following example, when the char is (for example) t, it echos the correct number of occurrences of t in var, but ...
stackoverflow.com
https://linuxhint.com/read_file_line_by_line_bash/
How to read file line by line in Bash script
I am a trainer of web programming courses. I like to write article or tutorial on various IT topics. I have a YouTube channel where many types of tutorials based on Ubuntu, Windows, Word, Excel, WordPress, Magento, Laravel etc. are published: Tutorials4u H
linuxhint.com
728x90