How to grep using a line break in regular expressions?


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
How to grep using a line break in regular expressions?

Hi,

I have a file as below,

{####
if file
then
file
else
file
}
print file

i need to fine the count of all the pattern - file, inside the { }

i'm using a grep command as

grep -c \{'[a-zA-Z0-9 ]*file[a-zA-Z0-9 ]*'\} fake.sh\

It doesn't gives me any result, i think the problem here is the line breaks in the paranthesis, so how can i include the line breaks in the regular expression???

Need ur suggestions!!

Thanks
# 2  
Try:

sed -n '/{/,/}/ { /file/ p}' file | wc -l
# 3  
have you solved your problem you posted here
# 4  
Quote:
Originally Posted by ghostdog74
have you solved your problem you posted here

The script u have provided doesn't works,

I'm working in KSH, will that be a problem?

---------- Post updated at 12:42 AM ---------- Previous update was at 12:40 AM ----------

Quote:
Originally Posted by dennis.jacob
Try:

sed -n '/{/,/}/ { /file/ p}' file | wc -l
Thanks for the response,

But it throws this error

sed: Function /{/,/}/ { /file/ p} cannot be parsed.

Please note i'm working in KSH
# 5  
Quote:
Originally Posted by divak
The script u have provided doesn't works,

I'm working in KSH, will that be a problem?
then why didn't you update on that thread that it doesn't work instead of starting a similar one? have you tried the rest of the solutions? by the way, just a simple grep like that would not solve your problem.
# 6  
Bug

Quote:
Originally Posted by ghostdog74
then why didn't you update on that thread that it doesn't work instead of starting a similar one? have you tried the rest of the solutions? by the way, just a simple grep like that would not solve your problem.
That's my mistake

However, it was a lot of learning.

I'm new to shell scripts and i don't have any idea on this.

Could u pls make this work? it would be really helpful.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #910
Difficulty: Easy
In C, you can declare a pointer as follows: data_type * pointer_variable_name;
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep and regular expressions

Hi All, For the past many days I have solved a lot of grep and regular expression questions, Now I am in a search for a good quality set of questions that can help me build and check my knowledge of grep with regular expressions, it would be great if anyone could help me with my requirement. ... (1 Reply)
Discussion started by: rahulkalra9
1 Replies

2. Homework & Coursework Questions

Regular Expressions with GREP

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Given a text file (big_english.txt) containing roughly 250,000 words, answer the following using grep and... (2 Replies)
Discussion started by: blahblahblah123
2 Replies

3. UNIX for Dummies Questions & Answers

extract columns using grep or regular expressions

I am trying to print columns from a table whose name (header) matches a certain string. E.g., patient1001 patient1002 patient2005 patient3005 patient4001 0 0 0 0 0 2 9 2 8 3 2 7 3 0 2 Say I want to print columns whose names end with "01" patient1001 patient4001 0 0 2 3 2 2 ... (3 Replies)
Discussion started by: quextil
3 Replies

4. UNIX for Advanced & Expert Users

What is the difference between single line mode and multiline mode in Regular expressions?

Hi All, Can please let me know what is the difference between the single line mode and multi line mode in regular expresions? Thanks, Chidhambaram B (3 Replies)
Discussion started by: chidhu.anu
3 Replies

5. Shell Programming and Scripting

Grep regular expression to get part of a line

Hi I just started on GNU Grep with regex and am finding it very challenging and need to ask for help already... here is the problem, I have a page (MYFILE) which consists of the following.... <div> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden"... (2 Replies)
Discussion started by: noobie74645
2 Replies

6. Homework & Coursework Questions

Regular expressions output is whole line

Hi, I am newbie in shell programming and I need some help. I had some data and I format it in a file like dn: uid=aaaaa, dc=exmple, dc=com cn: bbbb cccc sn: cccc telephoneNumber:+30-6543-123456 I have to extract the information aaaaa , bbbb, cccc and the phone number using awk... (3 Replies)
Discussion started by: pro
3 Replies

7. Shell Programming and Scripting

searching regular expressions with special characters like dot using grep

hi everybody I am a new user to this forum and its previous posts have been very useful. I'm searching in a file using grep for patterns like 12.13.444 55.44.443 i.e. of form <digit><digit>.<digit><digit>.<digit><digit><digit> Can anybody help me with this. Thanks in advance (4 Replies)
Discussion started by: jpriyank
4 Replies

8. Homework & Coursework Questions

Regular Expressions as command line paramteters

Use and complete the template provided. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: We have to write a program that uses wget to get pages of a URL and search them for a pattern. the command for the script should will look like this... (5 Replies)
Discussion started by: njmiano
5 Replies

9. UNIX for Dummies Questions & Answers

grep and regular expressions :

I wrote a simple korn shell where I am trying to filter all the good record layouts of a file to only leave the bad ones to look at. That file is hudge. Aside from '# comments' and 'var=ssss', all record should follow a specific record layout, with comma seperated fields. Some fields can have any... (2 Replies)
Discussion started by: Browser_ice
2 Replies

10. UNIX for Dummies Questions & Answers

More Grep - Regular Expressions

Hey all! I'm trying to search a file and return all instances of a word, let's say 'foo' in this case, as long as it's not a function name. For example: 1) int foo; //OK 2) //'this is totally fooed up' is also OK 3) int foo (int x, int y) //not ok to return I've tried a lot of regular... (7 Replies)
Discussion started by: Jombee
7 Replies

Featured Tech Videos