Sponsored Content
Full Discussion: Counting a chars IF == "x"
Top Forums Shell Programming and Scripting Counting a chars IF == "x" Post 302285175 by silkiechicken on Saturday 7th of February 2009 03:46:13 PM
Old 02-07-2009
Data Counting a chars IF == "x"

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.



https://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?



https://www.unix.com/unix-dummies-questions-answers/58760-counting-occurence-particular-characters.html
From this one, I don't have seperators between the characters


https://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
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. Shell Programming and Scripting

Removing " " chars using Awk

HI Friends, I am trying to elliminate the " " characters from the word: "hello" using awk. I need the output to be just = hello (without " " chars). Is there any way to do this ? Thanks! (3 Replies)
Discussion started by: vijaya2006
3 Replies

3. UNIX for Dummies Questions & Answers

How to replace special chars like " ' " (Apostrophe)

I'm goin to drive crazy soon, if i can not do this. I have a text file (570kb) and i have to replace the apostrophe " ' " and minus "-" with space " ". i have done it for minus: sed 's/-/ /g' aaa.txt >zzz.txt this replaced minus with space. but i can not use the same command for ' . ... (4 Replies)
Discussion started by: onculo
4 Replies

4. Shell Programming and Scripting

Delete chars after dot "."

Hi, I require to delete all characters after a dot "." from a string. For e.g. input_var="/home/dips/file_1_20100726.txt.gz /home/dips/file_2_20100726.txt.gz /home/dips/file_3_20100726.txt.gz" output_var="/home/dips/file_1_20100726 /home/dips/file_2_20100726... (3 Replies)
Discussion started by: dips_ag
3 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. UNIX for Dummies Questions & Answers

Counting vowels in string. "Comparison pointer-integer".

I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Discussion started by: fakuse
1 Replies

7. Programming

Bug in "Word Counting" Program

I have written a simple program that counts the number of words in the input stream. There is a small bug in the code and i am not able to figure out the cause of this bug. #include <stdio.h> int main() { int ichar = 0; int in_word = 1; // in_word = 1 *outside a word* in_word = 0... (4 Replies)
Discussion started by: sreeharshasn
4 Replies

8. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
SEQDIAG(1)						      General Commands Manual							SEQDIAG(1)

NAME
seqdiag - generate sequence-diagram image file from spec-text file. SYNOPSIS
seqdiag [options] file DESCRIPTION
This manual page documents briefly the seqdiag commands. seqdiag is generate sequence-diagram image file from spec-text file. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For a complete description, see the Info files. --version show program's version number and exit -h, --help show this help message and exit -a, --antialias Pass diagram image to anti-alias filter -c FILE, --config=FILE read configurations from FILE -o FILE write diagram to FILE -f FONT, --font=FONT use FONT to draw diagram -T TYPE Output diagram as TYPE format SEE ALSO
The programs are documented fully by http://tk0miya.bitbucket.org/seqdiag/build/html/index.html AUTHOR
seqdiag was written by Takeshi Komiya <i.tkomiya@gmail.com> This manual page was written by Kouhei Maeda <mkouhei@palmtb.net>, for the Debian project (and may be used by others). May 21, 2011 SEQDIAG(1)
All times are GMT -4. The time now is 12:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy