Sponsored Content
Full Discussion: Matching string
Top Forums UNIX for Dummies Questions & Answers Matching string Post 302168491 by earnstaf on Monday 18th of February 2008 02:20:31 PM
Old 02-18-2008
Quote:
Originally Posted by robotronic
Is it a game? Smilie

Code:
WORD="nasty"

while true
do
   echo -e "Input a char: \c"
   read CHAR
   CHARS="${CHARS}${CHAR}"
   echo "$WORD" | sed "s/[^${CHARS}]/-/g"
done

That's a cool way to go about doing a hangman type game. Should be pretty easy to have it pick a random dictionary word to use for $WORD and then give a certain number of guesses and decrement the count each time a wrong letter is guessed. Thanks for killing time for me at work on a Holiday Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

matching alphanumeric string

how to match an alphanumeric string like the following. i have to do like the following. if the input line is the data is {clock_91b} i have to replace that with the string was ("clock_91b") i tried like $line =~ s/the data is\s+\{(+)\}/the string was \(\"$1\"\)/ which... (4 Replies)
Discussion started by: sskb
4 Replies

2. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

3. Shell Programming and Scripting

String matching

for a certain directory, I want to grep a particular file called ABCD so what I do is ls /my/dir | grep -i "ABCD" | awk '{print $9}' however, there is also this file called ABCDEFG, the above command would reurn both file when I only want ABCD, please help! (3 Replies)
Discussion started by: mpang_
3 Replies

4. Shell Programming and Scripting

string matching in perl

Hi, I have to search for a string in a variable. Say the variable is var1='ERROR: Make java] as enabled' here i want to match which are in red color. other like abc etc could change. Can you tell me the exact command something like the below in perl if ($var1=~ m/ERROR: Make... (3 Replies)
Discussion started by: ammu
3 Replies

5. Shell Programming and Scripting

matching a string

I have a requirement of shell script where i need to read the File name i.e ls -t | head -1 and Match that Filename with some delimited values which are in a separate File. For Example i am reading the File name i.e (ls -t | head -1) after that i need to read one more sequential file which... (2 Replies)
Discussion started by: dsdev_123
2 Replies

6. Shell Programming and Scripting

Matching 2 items in a string

Little lost here, I am trying to search a line for both values after the $ signs. My ultimate goal is to get percertage. <?php $string = "Something on sale for $4 and orginal price $10"; $strstr =. strstr($string, '$'); $strrchr =. strrchr($string, '$'); echo "$strstr<br>"; echo... (1 Reply)
Discussion started by: mrlayance
1 Replies

7. Shell Programming and Scripting

String matching

I have a string like ab or abc of whatever length. But i want to know whether another string ( for example, abcfghijkl, OR a<space> bcfghijkl ab<space> cfghijkl OR a<space>bcfghijkl OR ab<space> c<space> fghijkl ) starts with ab or abc... space might existing on the longer string... If so, i... (4 Replies)
Discussion started by: nram_krishna@ya
4 Replies

8. Shell Programming and Scripting

Matching string from input to string of file

Hi, i want to know how to compare string of file with input string im trying following code: file_no=`paste -s -d "||||\n" a.txt | cut -c 1` #it will return collection number from file echo "enter number" read " curr_no" if ; then echo " current number already present" fi ... (4 Replies)
Discussion started by: a_smith
4 Replies

9. Shell Programming and Scripting

String matching using awk

Hello, I am working with google ngram data set which is of size 100s of gb. Before using it with Java, I wanted to filter it out using shell script. Here is a sample line in the file: 2.55 1.57 1992 10 20 30 The first two fields (2.55 and 1.57) are... (3 Replies)
Discussion started by: shekhar2010us
3 Replies

10. UNIX for Dummies Questions & Answers

Matching string

Hello all, i am trying to match a string and based on that proceed with my script or error out... i have a file called /tmp/sta.log that will be populated by oracle's spooling..it can have a output of either 2 of the below (OPEN or errors/ORACLE not avaiable) $ cat /tmp/sta.log OPEN $ $... (2 Replies)
Discussion started by: abdul.irfan2
2 Replies
monitor(3C)						   Standard C Library Functions 					       monitor(3C)

NAME
monitor - prepare process execution profile SYNOPSIS
#include <mon.h> void monitor(int (*lowpc(), int (*highpc)(), WORD *buffer, size_t bufsize, size_t nfunc); DESCRIPTION
The monitor() function is an interface to the profil(2) function and is called automatically with default parameters by any program created by the cc(1B) utility with the -p option specified. Except to establish further control over profiling activity, it is not necessary to explicitly call monitor(). When used, monitor() is called at least at the beginning and the end of a program. The first call to monitor() initiates the recording of two different kinds of execution-profile information: execution-time distribution and function call count. Execution-time distribution data is generated by profil() and the function call counts are generated by code supplied to the object file (or files) by cc(1B) -p. Both types of information are collected as a program executes. The last call to monitor() writes this collected data to the output file mon.out. The name of the file written by monitor() is controlled by the environment variable PROFDIR. If PROFDIR does not exist, the file mon.out is created in the current directory. If PROFDIR exists but has no value, monitor() does no profiling and creates no output file. If PROFDIR is dirname, and monitor() is called automatically by compilation with cc -p, the file created is dirname/pid.progname where progname is the name of the program. The lowpc and highpc arguments are the beginning and ending addresses of the region to be profiled. The buffer argument is the address of a user-supplied array of WORD (defined in the header <mon.h>). The buffer argument is used by moni- tor() to store the histogram generated by profil() and the call counts. The bufsize argument identifies the number of array elements in buffer. The nfunc argument is the number of call count cells that have been reserved in buffer. Additional call count cells will be allocated auto- matically as they are needed. The bufsize argument should be computed using the following formula: size_of_buffer = sizeof(struct hdr) + nfunc * sizeof(struct cnt) + ((highpc-lowpc)/BARSIZE) * sizeof(WORD) + sizeof(WORD) - 1 ; bufsize = (size_of_buffer / sizeof(WORD)); where: o lowpc, highpc, nfunc are the same as the arguments to monitor(); o BARSIZE is the number of program bytes that correspond to each histogram bar, or cell, of the profil() buffer; o the hdr and cnt structures and the type WORD are defined in the header <mon.h>. The default call to monitor() is as follows: monitor (&eprol, &etext, wbuf, wbufsz, 600); where: o eprol is the beginning of the user's program when linked with cc -p (see end(3C)); o etext is the end of the user's program (see end(3C)); o wbuf is an array of WORD with wbufsz elements; o wbufsz is computed using the bufsize formula shown above with BARSIZE of 8; o 600 is the number of call count cells that have been reserved in buffer. These parameter settings establish the computation of an execution-time distribution histogram that uses profil() for the entire program, initially reserves room for 600 call count cells in buffer, and provides for enough histogram cells to generate significant distribution- measurement results. For more information on the effects of bufsize on execution-distribution measurements, see profil(2). EXAMPLES
Example 1 Example to stop execution monitoring and write the results to a file. To stop execution monitoring and write the results to a file, use the following: monitor((int (*)())0, (int (*)())0, (WORD *)0, 0, 0); Use prof to examine the results. USAGE
Additional calls to monitor() after main() has been called and before exit() has been called will add to the function-call count capacity, but such calls will also replace and restart the profil() histogram computation. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
cc(1B), profil(2), end(3C), attributes(5), prof(5) SunOS 5.11 29 Dec 1996 monitor(3C)
All times are GMT -4. The time now is 04:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy