I have pipe delimited file, I want to check for value 'America' at 5th position (column) of each record.
America word can appear in any other columns as well, so grep -o
is not giving correct result.
Any other way to check the occurrence of word at specific location when file is delimited?
Asked
Active
Viewed 39 times
0
-
What do you mean by _check for value_? Do you want to count the occurrences? Do you want to test just whether 'America' appears at 5th position in any record? Do you want to print each cell at 5th position where 'America' appears? Do you want to print each record where 'America' appears at 5th position? – Armali Jan 08 '19 at 07:19
-
It works. Thank you much – dnyan Jan 08 '19 at 07:20
-
1Armali -- i was just wanted to check the count of records where 'America' appears at 5th positions – dnyan Jan 08 '19 at 07:27
1 Answers
0
Script like this can do the work
awk '$5="America" {print}' filename|wc -l
Of course you can do it only with awk like this:
awk 'BEGIN {i=0} $5="America" {i+=1} END {print i}' filename
To use different delimiter you can use in awk
this way:
awk -F\| 'BEGIN {i=0} $5="America" {i+=1} END {print i}' filename

Romeo Ninov
- 6,538
- 1
- 22
- 31
-
1cut -f11 -d '|' filename | grep 'America' | wc -l this works perfectly also – dnyan Jan 08 '19 at 07:33