Sponsored Content
Top Forums Shell Programming and Scripting Counting the number of occurances of all characters (a-z) in a string Post 302125980 by kahuna on Monday 9th of July 2007 11:26:02 AM
Old 07-09-2007
rsendhilmani,

This had me puzzled for a while, but I think I figured out what is wrong. I found this
Quote:
Because the transliteration table is built at compile time, neither the SEARCHLIST nor
the REPLACEMENTLIST are subjected to double quote interpolation. That means that
if you want to use variables, you must use an eval():
So the tr command is trying to translate the letters "$", "v", "a", and "l", not the value that $val contains.

Try
Code:
eval "\$count = (\$string =~ tr/$val//)";

Or use the s/// instead
Code:
$count = $string =~ s/$val//g;

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting Occurances in Two Files

I have two files I want to compare, one is a list of variables and the other is a text file COBOL program. Basically what I want to do is display only those variables that appear in the COBOL program only once. However I would also accept a count of each variable as it appears in the COBOL... (2 Replies)
Discussion started by: Keith Gergel
2 Replies

2. UNIX for Dummies Questions & Answers

count the number of files which have a search string, but counting the file only once

I need to count the number of files which have a search string, but counting the file only once if search string is found. eg: File1: Please note that there are 2 occurances of "aaa" aaa bbb ccc aaa File2: Please note that there are 3 occurances of "aaa" aaa bbb ccc... (1 Reply)
Discussion started by: sudheshnaiyer
1 Replies

3. Shell Programming and Scripting

number of characters in a string

Hi there, I have some user input in a variable called $VAR, and i need to ensure that the string is 5 or less characters .... does anybody know how i can count the characters in the variables ? any help would be great, cheers (2 Replies)
Discussion started by: rethink
2 Replies

4. Shell Programming and Scripting

How to count number of occurances of string in a file?

Gurus, Need little guidance. I have A.txt and B.txt file. B.txt file contains Unique strings. Sample content of B.txt file for which i cut the fourth column uniquely and output directed to B.txt file And A.txt file contains the above string as a fourth column which is last column. So A.txt... (7 Replies)
Discussion started by: Shirisha
7 Replies

5. UNIX for Dummies Questions & Answers

AWK - number of specified characters in a string

Hello, I'm new to using AWK and would be grateful for some basic advice to get me started. I have a file consisting of 10 fields. Initially I wish to calculate the number of . , ~ and ^ characters in the 9th field ($9) of each line. This particular string also contains alphabetical... (6 Replies)
Discussion started by: Olly
6 Replies

6. UNIX for Dummies Questions & Answers

counting occurrence of characters in a string

Hello, I have a string like this 0:1:2:0:2:2:4:0:0:0:-200:500...... what i want is to break down how many different characters are there and their count. For example for above string it should display 0 - 5 times 1 - 1 times 2 - 3 times 4 - 1 times . . . I am stuck in writing... (8 Replies)
Discussion started by: exit86
8 Replies

7. Shell Programming and Scripting

Counting number of records with string row delimiter

HI, i have a file like this t.txt f1|_f2|_ f1|_f2|_ f1|_f2|_ as if col delimiter is |_ and row delimiter |_\n trying to count number of records using awk $ awk 'BEGIN{FS="|_" ; RS="~~\n"} {n++}END{print n} ' t.txt 7 wondering how can i count this to 3 ? thx (9 Replies)
Discussion started by: aksforum
9 Replies

8. Shell Programming and Scripting

counting the number of characters in the filename of all files in a directory?

I am trying to display the output of ls and also print the number of characters in EVERY file name. This is what I have so far: #!/bin/sh for x in `ls`; do echo The number of characters in x | wc -m done Any help appreciated (1 Reply)
Discussion started by: LinuxNubBrah
1 Replies

9. Shell Programming and Scripting

Counting the number of characters

Hi all, Can someone help me in getting the following o/p I/p:... (7 Replies)
Discussion started by: Sri3001
7 Replies

10. Shell Programming and Scripting

Counting number of single quotes in a string

i need to be able to count the number of single quotes ' in the entire string below: "description":"DevOps- Test VM's, System Admins Test VM's ", awk can most likely do this, but here's my attempt using egrep: echo "${STRING}" | egrep -wc '"'"\'"'"' or echo "${STRING}" | egrep -wc... (11 Replies)
Discussion started by: SkySmart
11 Replies
Stream(3o)							   OCaml library							Stream(3o)

NAME
Stream - Streams and parsers. Module Module Stream Documentation Module Stream : sig end Streams and parsers. type 'a t The type of streams holding values of type 'a . exception Failure Raised by parsers when none of the first components of the stream patterns is accepted. exception Error of string Raised by parsers when the first component of a stream pattern is accepted, but one of the following components is rejected. === Stream builders Warning: these functions create streams with fast access; it is illegal to mix them with streams built with [< >]; would raise Failure when accessing such mixed streams. === val from : (int -> 'a option) -> 'a t Stream.from f returns a stream built from the function f . To create a new stream element, the function f is called with the current stream count. The user function f must return either Some <value> for a value or None to specify the end of the stream. val of_list : 'a list -> 'a t Return the stream holding the elements of the list in the same order. val of_string : string -> char t Return the stream of the characters of the string parameter. val of_channel : Pervasives.in_channel -> char t Return the stream of the characters read from the input channel. === Stream iterator === val iter : ('a -> unit) -> 'a t -> unit Stream.iter f s scans the whole stream s, applying function f in turn to each stream element encountered. === Predefined parsers === val next : 'a t -> 'a Return the first element of the stream and remove it from the stream. Raise Stream.Failure if the stream is empty. val empty : 'a t -> unit Return () if the stream is empty, else raise Stream.Failure . === Useful functions === val peek : 'a t -> 'a option Return Some of "the first element" of the stream, or None if the stream is empty. val junk : 'a t -> unit Remove the first element of the stream, possibly unfreezing it before. val count : 'a t -> int Return the current count of the stream elements, i.e. the number of the stream elements discarded. val npeek : int -> 'a t -> 'a list npeek n returns the list of the n first elements of the stream, or all its remaining elements if less than n elements are available. OCamldoc 2012-06-26 Stream(3o)
All times are GMT -4. The time now is 11:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy