View a file and count all words beginning with specificletter


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers View a file and count all words beginning with specificletter
# 8  
Old 03-30-2019
It helps to know what operating system and shell you're using since the utilities on various operating systems have options that might help with what you are trying to do that are not available on other operating systems. Whenever you start a new thread here, please always tell us what shell and operating system you're using.

We need a much clearer definition of what you consider to be a word starting with "s" or "S". Is a word just alphabetic characters? Can hyphens be included in a word (e.g., sub-sonic)? Can numeric characters be included in a word (e.g., "straight-6")? Can apostrophes be included in a word (e.g., "she's")? When apostrophes can be included in words, how are we to distinguish between a phrase surrounded by single-quotes and a word containing a hyphen? (Note that regular expressions in grep can only look at a single line and quoted strings can cross many line boundaries.)

And, if we can't see a sample of the data you're working with and the output you expect to get from it, we have no way to verify that anything we might suggest might work for you. Please give us a representative sample input and the corresponding exact output you hope to produce from that input.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count words from file

hi all how to count words from a text aaa bbb ccc ddd 123 aaa 123 aaa aaa ddd 123 i need to cout hoe many time the words "aaa" and "123" each appears the output should be 4 3 or 4 3 or aaa 4 123 3 thanks (10 Replies)
Discussion started by: sharong
10 Replies

2. Shell Programming and Scripting

Add words in beginning , end after removing a word in a file

My file has the entries like below... /dev/sds /dev/sdak /dev/sdbc /dev/sdbu I want to make the file like below echo 1 > /sys/block/sds/device/rescan echo 1 > /sys/block/sdak/device/rescan echo 1 > /sys/block/sdbc/device/rescan echo 1 > /sys/block/sdbu/device/rescan (2 Replies)
Discussion started by: saravanapandi
2 Replies

3. UNIX for Dummies Questions & Answers

Count dynamic words in file

Hello, i want built a log analyzer for nginx. Okay and i use it as training for the shell tools. The most what i want i could relize. But i has trouble with dynamic things. I have the IP address extracted and has set the geo localtion for the ip. I would like to count the countries. With... (3 Replies)
Discussion started by: sisihagen
3 Replies

4. Shell Programming and Scripting

How count the number of two words associated with the two words occurring in the file?

Hi , I need to count the number of errors associated with the two words occurring in the file. It's about counting the occurrences of the word "error" for where is the word "index.js". As such the command should look like. Please kindly help. I was trying: grep "error" log.txt | wc -l (1 Reply)
Discussion started by: jmarx
1 Replies

5. Shell Programming and Scripting

problem to count number of words from file

hi every one i have written this simple shell for counting number of word that user need to find from file but i have get several error when run it. can someone tell me the problem ? echo "Enter the file name" read file echo "enter word" read word for i in \`cat $file` do if then... (1 Reply)
Discussion started by: nimafire
1 Replies

6. Shell Programming and Scripting

count frequency of words in a file

I need to write a shell script "cmn" that, given an integer k, print the k most common words in descending order of frequency. Example Usage: user@ubuntu:/$ cmn 4 < example.txt :b: (3 Replies)
Discussion started by: mohit_iitk
3 Replies

7. UNIX for Dummies Questions & Answers

Count Number Of lines in text files and append values to beginning of file

Hello, I have 50 text files in a directory called "AllFiles" I want to make a program that will go inside of the "AllFiles" Directory and count the number of lines in each individual text file. Then, the program will calculate how many more lines there are over 400 in each text file and... (7 Replies)
Discussion started by: motoxeryz125
7 Replies

8. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

9. Shell Programming and Scripting

Help in counting the no of repeated words with count in a file

Hi Pls help in solving my doubt.Iam having file like below file1.txt priya jenny jenny priya raj radhika priya bharti bharti Output required: I need a output like count of repeated words with name for ex: priya 3 jenny 2 (4 Replies)
Discussion started by: bha148
4 Replies

10. UNIX for Dummies Questions & Answers

Remove words beginning with a certain character from a file

Hi, how could you go about removing words that begin with a certain character. assuming that this character is '-' I currently have echo "-hello" | sed s/-/""/ which replaces the leading dash with nothing but I want to remove the whole word, even if there are multiple words beginning... (3 Replies)
Discussion started by: skinnygav
3 Replies
Login or Register to Ask a Question
wordexp(3C)															       wordexp(3C)

NAME
wordexp(), wordfree() - perform word expansions SYNOPSIS
DESCRIPTION
performs word expansions and places the list of expanded words into the structure pointed to by pwordexp. The words argument is a pointer to a string containing one or more words to be expanded. The expansions are the same as would be performed by the shell (see sh-posix(1)), if words were the part of a command line representing the arguments to a utility. Therefore, words must not contain an unquoted newline character or any of the unquoted shell special characters or except in the context of shell command substi- tution. If words contains an unquoted comment character, it is treated as the beginning of a token that interprets as a comment indicator, causing the remainder of words to be ignored. The structure type is defined in the header and includes the following members: A used to keep count of words matched by words. A used as a pointer to a list of expanded words. Also a used to indicate the number of slots to reserve at the beginning of stores the number of generated words into Each individual field created during field splitting or path name expansion is a separated word in the list. The words are in order as described in shell word expansions. The first pointer after the last word pointer is a null pointer. The expansion of special parameters (such as $$ or $*) is unspecified. It is the caller's responsibility to allocate the storage pointed to by pwordexp. allocates other space as needed, including memory pointed to by frees any memory associated with pwordexp from a previous call to The flags argument is used to control the behavior of The value of flags is the bitwise inclusive OR of zero or more of the following con- stants, which are defined in Append words generated to the ones from a previous call to Make use of If this flag is set, is used to specify how many null pointers to add to the beginning of In other words, points to null pointers, followed by word pointers, followed by a null pointer. Fail if command substitution is requested. The pwordexp argument was passed to a previous successful call to and has not been passed to The result is the same as if the application had called and then called without Do not redirect stderr to Report error on an attempt to expand an undefined shell variable. The flag can be used to append a new set of words to those generated by a previous call to The following rules apply when two or more calls to are made with the same value of pwordexp and without intervening calls to o The first call must not set All subsequent calls must set it. o All of the calls must set or all must not set it. o After the second and each subsequent call, points to a list containing the following: o Zero or more null pointers, as specified by and o Pointers to the words that were in the list before the call, in the same order as before. o Pointers to the new words generated by the latest call, in the specified order. o The count returned in is the total number of words from all of the calls. o The application can change any of the fields after a call to but if it does, it must reset them to the original value before a subsequent call, using the same pwordexp value, to or with the or flag. If words contains an unquoted newline, parentheses, or curly brackets in an inappropriate context, fails, and the number of expanded words is zero. Unless is set in flags, redirects stderr to for any utilities executed as a result of command substitution while expanding words. If is set, writes messages to stderr if syntax errors are detected while expanding words. If is set, has the same value for each call and the call using a given RETURN VALUE
Upon successful completion, returns zero; otherwise, it returns a nonzero value defined in to indicate the error: One of the unquoted characters parentheses, or braces appears in words in an inappropriate context. Reference to undefined shell variable when is set in flags. Command substitution requested when was set in flags. Attempt to allocate memory failed. Shell syntax error such as unbalanced parentheses or unterminated string. Internal error. If returns the error value and are updated to reflect any words that were successfully expanded. In other cases, they are not modified. AUTHOR
and were developed by OSF and HP. SEE ALSO
sh-posix(1), fnmatch(3C), glob(3C), regexp(5), thread_safety(5). STANDARDS CONFORMANCE
wordexp(3C)