Sponsored Content
Top Forums Shell Programming and Scripting How to search (grep?) filename for a string and if it contains this then... Post 302259663 by tuathan on Tuesday 18th of November 2008 04:43:50 PM
Old 11-18-2008
How to search (grep?) filename for a string and if it contains this then...

Hi i want to write a script that will search a filename e.g. test06abc.txt for a string and if it contains this string then set a variable equal to something:

something like:

var1=0

search <filename> for 06
if it contains 06 then
var1=1
else
var1=0
end if

but in unix script Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending to filename a string of text grep finds

I am wanting to automate a process that includes the step of appending to a filename a string of text that's contained inside the file. I.e. if filename A.fileA contains a string of text that reads 1234 after the phrase ABC, I want the shell script file to rename the file 1234_FileChecked_A.fileA.... (3 Replies)
Discussion started by: HLee1981
3 Replies

2. Shell Programming and Scripting

grep: RE error 41: No remembered search string.

Hi guys, I am currently facing a problem with my current script, the script basically monitor a list of process on the Unix system. If a process is down it will send a notification e-mail to me. Currently I am facing an error when running the script grep: RE error 41: No remembered search... (2 Replies)
Discussion started by: fkaba81
2 Replies

3. Shell Programming and Scripting

grep string and output filename

Hello, I have over 200 files and some of them have the string like "John price $200". I would like to grep the string. Then output the filename which found the string. I have the following script, but it ONLY output the string echo Please input list file name: read listn for file in `cat... (3 Replies)
Discussion started by: happyv
3 Replies

4. UNIX for Dummies Questions & Answers

grep for a search string

Hi, I want to grep one file for a search string and get the next 10 lines after the search string. for eg,in file tnsnames.ora,i have 100 entries.i want to search for one string and get the entry for that db. please help how to acheive this using awk or sed? Thanks. (11 Replies)
Discussion started by: raga
11 Replies

5. Shell Programming and Scripting

Search for string in filename, not file content

How can I search for a string in a filename? For example, I want to know if a filename (not the file contents) contains the string "test". (3 Replies)
Discussion started by: daflore
3 Replies

6. UNIX for Dummies Questions & Answers

How to search for string A OR string B using Grep?

Hi, This is what I have done so far which is wrong for some reason: grep -h "stringA | stringB" filename Thank in advance! (5 Replies)
Discussion started by: jboy
5 Replies

7. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

8. Shell Programming and Scripting

Grep string search

Hi All, I'm using aix flavour unix where im trying for the below kind of pattern to search in all the files in a directory. I tried with different possible combinations like grep -ir "out.*\transaction_ctry_code" * etc.... Pattern I'm trying for : out<any thing>country_cd Here i... (0 Replies)
Discussion started by: rmkganesh
0 Replies

9. Shell Programming and Scripting

How to grep for a string on a FILENAME?

I call my bash shell script "test.sh" and pass "admin_usr.txt" as an argument like below. ./test.sh admin_usr.txt Inside the "test.sh" i wish to check if the filename passed "admin_usr.txt" i.e "$1" contains the string "admin" or not ... which in this case it does. Note: I do not wish to... (5 Replies)
Discussion started by: mohtashims
5 Replies

10. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies
STAPRUN(8)						      System Manager's Manual							STAPRUN(8)

NAME
staprun - systemtap runtime SYNOPSIS
staprun [ OPTIONS ] MODULE [ MODULE-OPTIONS ] DESCRIPTION
The staprun program is the back-end of the Systemtap tool. It expects a kernel module produced by the front-end stap tool. Splitting the systemtap tool into a front-end and a back-end allows a user to compile a systemtap script on a development machine that has the kernel debugging information (need to compile the script) and then transfer the resulting kernel module to a production machine that doesn't have any development tools or kernel debugging information installed. Please refer to stappaths(7) for the version number, or run rpm -q systemtap (fedora/red hat) apt-get -v systemtap (ubuntu) OPTIONS
The staprun program supports the following options. Any other option prints a list of supported options. -v Verbose mode. -w Suppress warnings from the script. -u Load the uprobes.ko module. -c CMD Command CMD will be run and the staprun program will exit when CMD does. The '_stp_target' variable will contain the pid for CMD. -x PID The '_stp_target' variable will be set to PID. -o FILE Send output to FILE. If the module uses bulk mode, the output will be in percpu files FILE_x(FILE_cpux in background and bulk mode) where 'x' is the cpu number. This supports strftime(3) formats for FILE. -b BUFFER_SIZE The systemtap module will specify a buffer size. Setting one here will override that value. The value should be an integer between 1 and 4095 which be assumed to be the buffer size in MB. That value will be per-cpu if bulk mode is used. -L Load module and start probes, then detach from the module leaving the probes running. The module can be attached to later by using the -A option. -A Attach to loaded systemtap module. -d Delete a module. Only detached or unused modules the user has permission to access will be deleted. Use "*" (quoted) to delete all unused modules. -D Run staprun in background as a daemon and show it's pid. -R Rename the module to a unique name before inserting it. -r N:URI Pass the given number and URI data to the tapset functions remote_id() and remote_uri(). -S size[,N] Sets the maximum size of output file and the maximum number of output files. If the size of output file will exceed size , system- tap switches output file to the next file. And if the number of output files exceed N , systemtap removes the oldest output file. You can omit the second argument. var1=val Sets the value of global variable var1 to val. Global variables contained within a module are treated as module options and can be set from the staprun command line. ARGUMENTS
MODULE is either a module path or a module name. If it is a module name, the module will be looked for in the following directory (where 'VERSION' is the output of "uname -r"): /lib/modules/VERSION/systemtap Any additional arguments on the command line are passed to the module. One use of these additional module arguments is to set the value of global variables declared within the module. $ stap -p4 -m mod1 -e 'global var1="foo"; probe begin{printf("%s ", var1); exit()}' Running this with an additional module argument: $ staprun mod1.ko var1="HelloWorld" HelloWorld Spaces and exclamation marks currently cannot be passed into global variables this way. EXAMPLES
See the stapex(3stap) manual page for a collection of sample scripts. Here is a very basic example of how to use staprun. First, use stap to compile a script. The stap program will report the pathname to the resulting module. $ stap -p4 -e 'probe begin { printf("Hello World! "); exit() }' /home/user/.systemtap/cache/85/stap_8553d83f78c_265.ko Run staprun with the pathname to the module as an argument. $ staprun /home/user/.systemtap/cache/85/stap_8553d83f78c_265.ko Hello World! MODULE DETACHING AND ATTACHING
After the staprun program installs a Systemtap kernel module, users can detach from the kernel module and reattach to it later. The -L option loads the module and automatically detaches. Users can also detach from the kernel module interactively by sending the SIGQUIT sig- nal from the keyboard (typically by typing Ctrl-). To reattach to a kernel module, the staprun -A option would be used. FILE SWITCHING BY SIGNAL
After the staprun launched the stapio , users can command it to switch output file to next file when it outputs to file(s) (running staprun with -o option) by sending a SIGUSR2 signal to the stapio process. When it receives SIGUSR2, it will switch output file to new file with suffix .N where N is the sequential number. For example, $ staprun -o foo ... outputs trace logs to foo and if it receives SIGUSR2 signal, it switches output to foo.1 file. And receiving SIGUSR2 again, it switches to foo.2 file. SAFETY AND SECURITY
Systemtap is an administrative tool. It exposes kernel internal data structures and potentially private user information. See the stap(1) manual page for additional information on safety and security. To increase system security, only the root user and members of both stapdev and staprun groups can use staprun to insert systemtap mod- ules (or attach to existing ones). Members of the stapusr group only can use staprun to insert or remove systemtap modules (or attach to existing systemtap modules) under the following conditions: o The module is located in the /lib/modules/VERSION/systemtap directory. This directory must be owned by root and not be world writable. o The module has been signed by a trusted signer. Trusted signers are normally systemtap compile servers which sign modules when the --unprivileged option is specified by the client. See the stap-server(8) manual page for a for more information. FILES
/lib/modules/VERSION/systemtap If MODULE is a module name, the module will be looked for in this directory. Users who are only in the 'stapusr' group can install modules located in this directory. This directory must be owned by the root user and not be world writable. SEE ALSO
stap(1), stapprobes(3stap), stapfuncs(3stap), stap-server(8), stapex(3stap) BUGS
Use the Bugzilla link of the project web page or our mailing list. http://sourceware.org/systemtap/, <systemtap@sourceware.org>. STAPRUN(8)
All times are GMT -4. The time now is 05:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy