Sponsored Content
Top Forums Shell Programming and Scripting Escaping backslash and asterisk in egrep to match "\*" Post 302773791 by Chubler_XL on Thursday 28th of February 2013 04:52:56 PM
Old 02-28-2013
What you have appears to work fine for me:

Code:
$ cat testit
\*
$ od -c testit
0000000   \   *  \n
0000003
$ egrep '^(\\)\*$' testit
\*

 

10 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. UNIX for Dummies Questions & Answers

search ")" with egrep - egrep: syntax error

Hi Guys, we have a shell script which basically query the Database which retrieves huge data and use the data with "egrep" . Now there is some data which contains characters like "abc)" and the same is used like below : "egrep (.+\|GDPRAB16\|GDPR/11702 96 abc)\|$ temp.txt" now while... (7 Replies)
Discussion started by: sagarjani
7 Replies

3. UNIX for Dummies Questions & Answers

How to use the "grep/egrep" command to search files.

Hi Team, I am new to this forum and also trying to learn Unix. I will highly appriciate your help if you can help me to get the right command . {{{ I use the command " today | egrep '(10:| 11: )' | grep ERROR " to grep all the files that has been error betweeen 10 to 11... (6 Replies)
Discussion started by: rkhanal
6 Replies

4. 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

5. Shell Programming and Scripting

Disabling Backslash Interpretation with "echo -E"?

Hello All, In a Bash Script I'm writing I have a section where I loop through a text file that was outputted by another script. In the text file some of the strings in there are enclosed with the BOLD "character sequences" (i.e. "\033But it's weird, because if I run this command: echo -E... (12 Replies)
Discussion started by: mrm5102
12 Replies

6. Shell Programming and Scripting

sed command escaping backslash "/"

Hello friends/'unix experts', i have a file as below cat sample.txt satish /rakesh/ sandhya /sandeep/ i have to replace /rakesh/ with rakesh, how can i do it with sed, i tried below code but its throwing errors sed -e 's/'"\(/rakesh/)\"'/\1rakesh/g' sample.txt ... (1 Reply)
Discussion started by: only4satish
1 Replies

7. UNIX for Dummies Questions & Answers

Egrep confusion with "I" and "-I" pattern

I am executing following command egrep -w I filename.txt the filename.txt has following data .... -I 07-18 08:31:19.924 9880 6 SessionManager ConnectConfig: ConfigurationWebService LoginResults=SuccessfulLogin I am so hungry that I need to eat I expect egrep to print only the second... (1 Reply)
Discussion started by: VBG
1 Replies

8. UNIX for Advanced & Expert Users

AIX - io info get from "libperfstat" not match "iostat"

Hi, everyone. I need to write a program to get io info based on libperfstat. But the "write time" of a disk is just half of the value get from iostat. I'm confused and can't explain. Help please. How I calculate "write service time per sec": In iostat: write service... (0 Replies)
Discussion started by: jackliang
0 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

10. Shell Programming and Scripting

Search file containing ps results for a match "my.cnf" and then for a second match . "ok:" and

I need to find two matches in the output from ps. I am searching with ps -ef |grep mysql for: my.cnf /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/mysql/master/agis_core/etc/my.cnf after this match I want to search back and match the hostname which is x number of lines back, above the... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies
CPOOL(3)						     Common Library Functions							  CPOOL(3)

NAME
Cpool - LCG Pool inferface SYNOPSIS
#include <Cpool_api.h> int Cpool_create(int nbwanted, int * nbget); int Cpool_assign(int poolid, void *(*startroutine)(void *), void *arg, int timeout); int Cpool_next_index(int poolid); int Cpool_next_index_timeout(int poolid, int timeout); ERRORS
See Cthread corresponding section. DESCRIPTION
(Please read the NOTE section) Cpool is a layer built upon Cthread, the LCG Thread interface. It allows the user to create dedicated pools, and then to assign to one of them a given routine to execute. The created processes or threads will remain alive, unless the routines assigned to are crashing, or explicitly calling an exit statement, like exit() or pthread_exit(). Typical use might be writing a server, with a bunch of pre-created processes or pools (depending on the environment with which Cthread has been compiled), and assign to a given pool a routine with the socket file descriptor as argument address. In principle Cpool should be compiled with the same relevant flags with which Cthread has been. int Cpool_create(int nbwanted, int * nbget); This method is creating a pool of nbwanted processes or threads. If the second argument, nbget , is not NULL, its location will contain the number of effectively created threads or processes. Return value is the pool ID, a number greater or equal to zero, or -1 in case of error. int Cpool_assign(int poolid, void *(*startroutine)(void *), void *arg, int timeout); This method is assigning a routine to poolid as returned by Cpool_create, whose address is startroutine , that have the same prototype as every typical routine in multithread programming. This means that it returns a pointer, and it gets as entry a pointer identified by the arg parameter. The last argument is a possible timeout , in seconds, which will apply if it is greater than zero. If it is lower than zero, the assignment will wait forever until a thread is available. If it is equal to zero, the method will return immediately if no thread is available. Return value is 0 if success, or -1 in case of error. int Cpool_next_index(int poolid); int Cpool_next_index_timeout(int poolid, int timeout); Those methods returns that next available thread number that will be assigned if you ever call Cpool_assign immediately after. If you spec- ify a timeout lower or equal than zero, then this is a blocking method until one thread is available at least. Those methods, so, returns a number greater or equal than zero, and -1 if there is an error. NOTE
Arguments passing in a non-thread environment Since a forked process can only address its namespace data segment, the address of the arguments, if any, valid in its parent, will not be directly accessible for the child we are talking about. This means that Cpool, in a non-thread environment, have to trace-back all the memory allocation visible for the parent. Then, Cpool is not passing the address of the arguments, but its content to the child through a child-parent communication, monitored with a simple protocol. There are four cases: 1.The address is NULL: nothing will be transmitted to the child 2.The address is exactly a pointer returned by malloc() or realloc(): the full malloced area will be tranmitted. 3.The address is somewhere in a memory allocate block: the remaining memory block, e.g. starting from the address up to its end, will be transmitted. 4.the address do not point to any memory allocated area: Cpool will assume it is a pointer-like argument, probably to some static variables, visible for all processes, and will transmit the content of the memory pointed by the address, assum- ing it is coded on 64-bits. In any case, the user is passing a pointer, and the routine will see a pointer, pointing to a (hopefully, see the point 4., listed upper) same-content area. Arguments design to work on both thread and non-thread environments The thread and non-thread arguments can have conceptually a different design when dealing with arguments; In a thread environment, the routined passed to Cpool_assign, is sharing memory, so is allowed to free() the argument, because mem- ory is then shared. On the contrary, in a non-thread environment, this may be a segmentation fault. This means that it is recommended to use static variables, containing simple value, like an integer (for example: a socket file descriptor), and not allocated memory. If, neverthless, you persist to use free() in your routine, you can use the following trick: /* ------------------------ */ /* In the Caller Routine */ /* ------------------------ */ arg = malloc(...); if (! Cpool_assign(...)) { if (Cthread_environment() != CTHREAD_TRUE_THREAD) { /* Non-Thread environment */ free(arg); } else { /* Thread environment */ /* ... do nothing */ } } else { /* In cany case it is OK */ free(arg); } /* ------------------------ */ /* In the Execution Routine */ /* ------------------------ */ void *routine(void *arg) { ./.. if (Cthread_environment() == CTHREAD_TRUE_THREAD) { /* Thread environment */ free(arg); } else { /* Non-Thread environment */ /* ... do nothing */ } ./.. } EXAMPLE
#include <Cpool_api.h> #include <stdio.h> #include <errno.h> #define NPOOL 2 #define PROCS_PER_POOL 2 #define TIMEOUT 2 void *testit(void *); int main() { int pid; int i, j; int ipool[NPOOL]; int npool[NPOOL]; int *arg; pid = getpid(); printf("... Defining %d pools with %d elements each ", NPOOL,PROCS_PER_POOL); for (i=0; i < NPOOL; i++) { if ((ipool[i] = Cpool_create(PROCS_PER_POOL,&(npool[i]))) < 0) { printf("### Error No %d creating pool (%s) ", errno,strerror(errno)); } else { printf("... Pool No %d created with %d processes ", ipool[i],npool[i]); } } for (i=0; i < NPOOL; i++) { /* Loop on the number of processes + 1 ... */ for (j=0; j <= npool[i]; j++) { if ((arg = malloc(sizeof(int))) == NULL) { printf("### Malloc error, errno = %d (%s) ", errno,strerror(errno)); continue; } *arg = i*10+j; printf("... Assign to pool %d (timeout=%d) the %d-th routine 0x%x(%d) ", ipool[i],TIMEOUT,j+1,(unsigned int) testit,*arg); if (Cpool_assign(ipool[i], testit, arg, TIMEOUT)) { printf("### Can't assign to pool No %d (errno=%d [%s]) the %d-th routine ", ipool[i],errno,strerror(errno),j); free(arg); } else { printf("... Okay for assign to pool No %d of the %d-th routine ", ipool[i],j); If (Cthread_environment() != CTHREAD_TRUE_THREAD) { /* Non-thread environment: the child is in principle not allowed */ /* to do free himself */ free(arg); } } } } /* We wait enough time for our threads to terminate... */ sleep(TIMEOUT*NPOOL*PROCS_PER_POOL); exit(EXIT_SUCCESS); } void *testit(void *arg) { int caller_pid, my_pid; my_pid = getpid(); caller_pid = (int) * (int *) arg; if (Cthread_environment() == CTHREAD_TRUE_THREAD) { /* Thread environment : we free the memory */ free(arg); } printf("... I am PID=%d called by pool %d, try No %d ", my_pid,caller_pid/10,caller_pid - 10*(caller_pid/10)); /* * Wait up to the timeout + 1 */ sleep(TIMEOUT*2); return(NULL); } SEE ALSO
Cthread AUTHOR
LCG Grid Deployment Team LCG
$Date: 2010-04-05 09:51:26 +0200 (Mon, 05 Apr 2010) $ CPOOL(3)
All times are GMT -4. The time now is 05:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy