I'm having a file called sam1.txt and it has data is deliminted by ~.Find count of center under specific column called category?
how to count speck keyword is found in .txt file
shell script;awk;csv
Here's how I would do it:Get the first line using head.In that line, get the string up to Category using grep -o.Count the number of occurrences of ~ in that string using grep -c to figure out which column number contains the category.Get that column using awk -F'~' (possibly using tail to get rid of the first line).Get the categories containing center using grep, being careful to anchor the string on both sides to avoid matching things like off-center or centered.Finally, count the number of lines (that is, entries) with a category of center using wc -l.These commands are all well documented in their man pages.