How do i find "&variable[0]" using grep -r?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do i find "&variable[0]" using grep -r?
# 1  
Old 08-04-2014
How do i find "&variable[0]" using grep -r?

Guys,

i've got hundreds of C programs in my ~/devel/ directory and sub-directories. is there a way i can use grep -r followed by some zsh, sh, bash, to find some code that starts with "&foo[N]" or something similar?

thanks in advance!
# 2  
Old 08-04-2014
Code:
find . -name *.c | xargs grep '&foo[N]'


Last edited by Scott; 08-04-2014 at 05:15 PM.. Reason: Code tags
# 3  
Old 08-04-2014
What is "something similar"?
And, what do you mean by "starts with"? First line in file, or first chars in some line in that file.
# 4  
Old 08-04-2014
findinf &xyz[nnn] ...

find . -name *.c | xargs grep '&foo[N]'

brought xargs to mind. but two things here:

1. will your find clause get me only my .c files? [i hope, i hope]
2. will [A-Za-z] or somesuch work to replace "foo"?

basically, i'm looking for anunknown variable that is prepended with "&" and
ends with [N]. N is most likely 0.

thanks.
# 5  
Old 08-04-2014
How about
Code:
grep -Eri "\&[[:alpha:]]{1,3}\[[0-9]\]" *.c

# 6  
Old 08-04-2014
fin &Var[N]

Quote:
Originally Posted by RudiC
What is "something similar"?
And, what do you mean by "starts with"? First line in file, or first chars in some line in that file.
the ampersand is the first byte in the variable. it is an array that starts {probably} at 0.

---------- Post updated at 02:26 PM ---------- Previous update was at 02:08 PM ----------

Quote:
Originally Posted by RudiC
How about
Code:
grep -Eri "\&[[:alpha:]]{1,3}\[[0-9]\]" *.c


Yes! probably this kind of voodoo may do the trick. A day ago, a guy i've known for many years shows me how-to copy a string array into a Global variable that i may use [or may NOT] use. his code is old and needs a few tweaks. no problem. i am trying to understand how the file foo.16.text can be copied into (global) char *GtkLabelBar[256];

but before i just-do-it, i need to understand why his example works. i have found many ancient examples; want to print them out so i can get some clues.

Once i see it, i'll continue.
# 7  
Old 08-04-2014
Note that grep -r statement will not find *.c files in subdirectories. The find statement will also fail to do that if the are any *.c files present in the current directory . In both cases *.c is expanded by the shell and the the result is provided as parameters to the command. To find all *.c files *.c needs to be quoted:
Code:
find . -name '*.c' -exec grep -E '&[[:alpha:]]+\[[0-9]+\]' {} +

Another thing is that xargs will break things if there are spaces in the filename. The example shows how it could be done without xargs, by using -exec . The + sign makes it at least as efficient as xargs

Last edited by Scrutinizer; 08-04-2014 at 08:48 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find files in sub dir with tag & add "." at the beginning [tag -f "Note" . | xargs -0 {} mv {} .{}]

I am trying find files in sub dir with certain tags using tag command, and add the period to the beginning. I can't use chflags hidden {} cause it doesn't add period to the beginning of the string for web purpose. So far with my knowledge, I only know mdfind or tag can be used to search files with... (6 Replies)
Discussion started by: Nexeu
6 Replies

2. Shell Programming and Scripting

Using "Find" & Storing To Multiple Variables

Hello all! I'm pretty new to bash scripting, so this should be a pretty easy question to solve. For the last few hours, I've been creating a script that will list some of the following (based on a path I specify): # of directories # of files # of executable files files older than 365... (2 Replies)
Discussion started by: alphekka
2 Replies

3. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

4. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

5. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

6. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

7. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

8. Shell Programming and Scripting

Grep & EMail "HOW to quit ??? "

Hello All, I am using the below code to grep particular word from file and then emailing it through mail command. the problem is this that when i run the script so it stops and ask me for the mail body then it asks for cc: and then runs. I dont want to give body and cc: address, i just want... (1 Reply)
Discussion started by: wakhan
1 Replies

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

10. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies
Login or Register to Ask a Question