![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Count first column on the basis of two other columns | kaustubh137 | Shell Programming and Scripting | 1 | 05-29-2008 08:54 AM |
| How to get the count only if two column matches? | gobinath | Shell Programming and Scripting | 3 | 05-27-2008 04:01 AM |
| nawk-how count the number of occurances of a pattern, when don't know the pattern | cyber111 | Shell Programming and Scripting | 2 | 05-11-2008 03:00 AM |
| Count of matched pattern occurance | palash2k | UNIX for Dummies Questions & Answers | 3 | 04-24-2008 03:33 PM |
| Max column count in a file | gemini | Shell Programming and Scripting | 2 | 08-24-2004 12:12 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to count pattern in column
Hi,
I have another problem here on Bash. Assume I have an output file containing two columns which the second one contains :- abc`dgdf`sdfdg` dfgfg```ssd` I would like to count the "`" characters for each line (which is first column). I am wondering what command can I used other than AWK to calculate these characters for each line. I tried to use AWK by using if ($2)=="`", count[$1]=count++; however, it doesnt work. Please advise. Thanks. -Jason |
|
||||
|
Hi franklin,
Thanks for your reply. It works well, but I need to know more about this command. From the Field Separator "`", does that means NF is actually referring to the field separator since we have set only one in the BEGIN loop? If that is so, if i have other field separator let say '&' or '%' etc..how could I differentiate them using NF since NF to my understanding is referring to number of fields. Please advise. Thanks. Rgrds, Jason |
|
||||
|
The default fieldseperator of awk is a tab or spaces, which is change here with the BEGIN statement.
The fieldseperator is used as a trick to count the character. NF is the number of fields of each row so if you have 5 fields there will be 4 fieldseperators. Regards |
|
||||
|
Hi Franklin,
I agree with what you explained. But given the fact if I have one line consist of different patterns such as "`" (the one you showed me) and "$". or even more other patterns, If that is the case how can I use NF to differentiate these characters. For your information, my input is a line of statements which is something like below:- halo`world$$`` If using the method you showed me, we could have one NF tricked one at a time. How could we represent for both patterns in this case. Please advise. Hope you could get my meaning. Thanks. -Jason |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|