Sponsored Content
Full Discussion: bash search function
Top Forums Shell Programming and Scripting bash search function Post 302241950 by doze on Tuesday 30th of September 2008 04:29:39 PM
Old 09-30-2008
bash search function

I want to have a function with a similar interface:
Code:
search *.cpp asdf

that will search recursively all directories for *.cpp file, containing line 'asdf' inside. I tried this:
Code:
function search { find . -name "$1" | xargs grep -li $2; }

But it doesn't work all the time. For example, if i run it in dir1:
Code:
dir1
\dir2
\\file2.cpp
\file1.cpp

it only greps file1.cpp without going down to file2.cpp. I figured out it happens because of globbing *.cpp to the list of files in dir1, but i have no idea, how to avoid it in function without turning globbing off. Quotes do not help either. Any ideas?
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find function name based on word search

Hi All, I want to find out function name based on word. Here i ll give u one example I have several files based on below format. file will start and ends with same name only EX: file1.txt public function calculate1() { ---- ---- call Global Function1() ---- ---- } END... (9 Replies)
Discussion started by: spc432
9 Replies

2. Shell Programming and Scripting

BASH function error

Hey everyone. I am currently testing my first function based BASH script. The ultimate goal is going to be moving logs from point A to point B (or if B is down, to point C). Part of this involves the following function: function testAlive{ ping -c 1 -q $1 } Now when I run ping -c... (1 Reply)
Discussion started by: msarro
1 Replies

3. UNIX for Dummies Questions & Answers

If function to search for files

Hi, I need to concatenate two files as long as both files are present. As of now, I am using the following code: #!/bin/bash for y in {1..14} do cat -s $y.F $y.R > $y.1 done However, the outputfile is being generated even in the absent of both infiles. I would like to search for both... (2 Replies)
Discussion started by: Xterra
2 Replies

4. Shell Programming and Scripting

Bash function

startvm() { startguest } Is there a way use one line to get this ? actually I want startvm=startguest (5 Replies)
Discussion started by: yanglei_fage
5 Replies

5. Programming

Search function help

Hello again unix.com, I need a help with a search function on the website i'm building. http://auto-nonstop.ro/index.php?page=search --> when I press Apply the search fields of the plugin pops up... all i want to do is http://auto-nonstop.ro/index.php?page=search to be the page before I press... (1 Reply)
Discussion started by: galford
1 Replies

6. UNIX for Dummies Questions & Answers

Bash INKEY$ function...

This is probably common knowledge to the professionals but not so much for amateurs like myself. This is a code snippet for the equivalent of BASIC's... LET char$=INKEY$ As the timeout parameter cannot be less than 1 second then this is the only limitation... It is a single line... (5 Replies)
Discussion started by: wisecracker
5 Replies

7. Shell Programming and Scripting

Bash function problem

I am trying to figure out why I am having a "problem" with some functions in a bash script I am running. The reason for air quoting is that the functions are working, they are just not displaying anything to screen when called from another function. Here's an example: function Create_Input {... (6 Replies)
Discussion started by: dagamier
6 Replies

8. Shell Programming and Scripting

Bash to search file for string and lauch function if found

In the bash below I am searching the filevirus-scan.log for the Infected files: 0 line (in bold) and each line for OK. If both of these are true then the function execute is automatically called and processing starts. If both these conditions are not meet then the line in the file is sent to the... (2 Replies)
Discussion started by: cmccabe
2 Replies
CPP(1)							      General Commands Manual							    CPP(1)

NAME
cpp - C language preprocessor SYNOPSIS
cpp [ option ... ] [ ifile [ ofile ] ] DESCRIPTION
Cpp interprets ANSI C preprocessor directives and does macro substitution. The input ifile and output ofile default to standard input and standard output respectively. The options are: -Dname -Dname=def -Idir Same as in 2c(1). -M Generate no output except a list of include files in a form suitable for specifying dependencies to mk(1). Use twice to list files in angle brackets. -N Turn off default include directories. All must be specified with -I. Without this option, /$objtype/include and /sys/include are used as the last two searched directories for include directives, where $objtype is read from the environment. -V Print extra debugging information. -+ Understand C++ comments. The output file contains processed text sprinkled with lines that show the original input line numbering: #line linenumber "ifile" The input language is as described in the ANSI C standard. The C compilers do not use cpp; they contain their own simple but adequate pre- processor, so cpp is usually superfluous. FILES
/sys/include directory for machine-independent include files /$objtype/include directory for machine-dependent include files SOURCE
/sys/src/cmd/cpp SEE ALSO
2c(1) CPP(1)
All times are GMT -4. The time now is 08:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy