•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 455,976 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,797 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 988 | Replies: 9 | Solved
![]() |
•
•
Join Date: May 2006
Location: India
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Hi all,
I am writing a script which parses /* to find out the commented portion of the code.
I am using grep "/\*" file.c
Following is the code snippet
for i in `grep "/\*" file.c`; do
.
.
.
done
but this is not giving the lines greped from file.c.
However if I run this command from the shell i.e.
grep "/\*" file.c I get the correct answer, I think the problem is due to ` .
Can some body help me on this
TIA
tan...
I am writing a script which parses /* to find out the commented portion of the code.
I am using grep "/\*" file.c
Following is the code snippet
for i in `grep "/\*" file.c`; do
.
.
.
done
but this is not giving the lines greped from file.c.
However if I run this command from the shell i.e.
grep "/\*" file.c I get the correct answer, I think the problem is due to ` .
Can some body help me on this
TIA
tan...
•
•
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,012
Reputation:
Rep Power: 6
Solved Threads: 68
Try grep ///*
★ Homework Help ★ Freelance Programmer ★ Freelance Jobs ★
★ Build A Website ★ Interview Question And Answer ★ Tax Filing ★
★ Build A Website ★ Interview Question And Answer ★ Tax Filing ★
for i in `grep "/\\*" file.c`; do
You need to escape the escape character when doing this inside of the expression quotes.
Edit: Which, I believe, is what ithelp meant, but he mistakenly used /// instead of /\\.
Last edited by masijade : Nov 27th, 2007 at 6:27 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: May 2006
Location: India
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Thanks for reply
but that thing is still not working for me.
Here is the code
for i in `grep "/\\*" file `; do echo ">>>$i ";do
echo "$i"
done
Contents of file is simple
Line 1
LIne 2
/*
//
LIne 3
The output(mentioned below) is strange listing of / directory
/bin
/boot
/dev
/etc
/home
/initrd
/lib
/lost+found
/media
/misc
/mnt
/opt
/proc
/root
/sbin
/selinux
/srv
/sys
/tmp
/usr
/var
regards
tan...
but that thing is still not working for me.
Here is the code
for i in `grep "/\\*" file `; do echo ">>>$i ";do
echo "$i"
done
Contents of file is simple
Line 1
LIne 2
/*
//
LIne 3
The output(mentioned below) is strange listing of / directory
/bin
/boot
/dev
/etc
/home
/initrd
/lib
/lost+found
/media
/misc
/mnt
/opt
/proc
/root
/sbin
/selinux
/srv
/sys
/tmp
/usr
/var
regards
tan...
It is because of file name expansion in the shell.
Just for fun try it this way
Just for fun try it this way
for i in `grep "/\\*" file`; do set -f i=$i echo "$i" done
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Ok, unfortunately, the only thing left to do, that I can think of, is to do the script this way:
And start the entire script without file name generation. That means, however, that file name expansion/generation does not work at all in the script, which may be wholly unenjoyable, but at least this part works.
#!/bin/sh -f for i in `grep "/\\*" file`; do echo "$i" done
And start the entire script without file name generation. That means, however, that file name expansion/generation does not work at all in the script, which may be wholly unenjoyable, but at least this part works.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Different. Although I don't really know why sourcing the script, rather than simply running it, would make a difference in the way set -f acts, but, oh well.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- SQL Injection Attack (Database Design)
- Return values from Perl to asterisk (Perl)
- Voxzone X100P Card - Asterisk (PCI and Add-In Cards)
- *Pointer program problem. (C++)
- merged:nesting loops (C++)
- C++ help (C++)
- TO CHAINSAW - or anybody else who knows C++ (C++)
- Forms Authorization/ Authentication using asp .net and vb .net (ASP.NET)
Other Threads in the Shell Scripting Forum
- Previous Thread: Regarding Env variables
- Next Thread: Help to sort my script output?



Linear Mode