![]() |
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 |
| How to replace special chars like " ' " (Apostrophe) | onculo | UNIX for Dummies Questions & Answers | 4 | 10-26-2008 09:59 PM |
| Removing " " chars using Awk | vijaya2006 | Shell Programming and Scripting | 3 | 04-07-2008 12:13 PM |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 03:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 04:15 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I'm new at this script stuff... only have minor exposure to java.
My problem is largely syntax and being unable to figure out what the manuals are telling me what each option does. Basically I have a hard time understanding the documentation and need help with what awk is capable of on the shell command line. I have a file and if the line does not start with a ">" I want to count all the characters but not spaces. Just [A-Z]. In this case I know the characters are going to be A E or Z. My thinking has got me this far so far.. If myfile is "ATHROUGHZ SPACES" grep -v ">" myfile.tab | awk if nextChar == "A || E || Z" {++count} END {print count}' I want it to return 4, because there are two A, one E and one Z. The grep part was to select for the lines that did not contain ">". The {++count} END {print count}' part is to count and then print the count However I am stuck in the middle part which is highlighted in red. I haven't found (or understood how to use) anything that lets me go through the line character by character to compare it with if it is a desired letter and count it if it is a match. I found the following threads but don't understand them enough to apply them to my situation. http://www.unix.com/shell-programming-scripting/9721-counting-characters.html From this one it appears that -F won't work to seperate the characters because it is used to seperate strings? http://www.unix.com/unix-dummies-questions-answers/58760-counting-occurence-particular-characters.html From this one, I don't have seperators between the characters http://www.unix.com/shell-programming-scripting/39765-counting-number-occurances-all-characters-z-string.html This thread is in reference to PEARL which I am not familar with, and not sure how is to be applied to just the command line? If anyone has any suggestions or good directions to point me for what feels like should be incredibly easy to do, it would be awesome! Thanks a bunch! -Diana |
|
||||
|
Thank you for the reply.
I don't know anything about PEARL yet, but I am sure your example there will be useful once I can read up on it more. I'm about 30 hours in to my first Linux style command line experience so am still a n00b. |
|
|||||
|
To count chars in the A-Z range
Code:
$ echo 'ATHROUGHZ SPACES' | nawk '!/^>/ {print gsub(/[A-Z]/, "")}'
15
$ echo '>ATHROUGHZ SPACES' | nawk '!/^>/ {print gsub(/[A-Z]/, "")}'
Code:
$ echo 'ATHROUGHZ SPACES' | nawk '!/^>/ {print gsub(/[^ ]/, "")}'
15
$ echo '>ATHROUGHZ SPACES' | nawk '!/^>/ {print gsub(/[^ ]/, "")}'
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|