CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
grep long string

 



zivsegal
Novice

Jun 24, 2009, 7:25 AM

Post #1 of 7 (896 views)
grep long string Can't Post

Hi,

I have read a file into variable $document using
---------------------------------------------------
my $document = do {
local $/ = undef;
open my $fh, "<", $c
or die "could not open $file: $!";
<$fh>;
};
-----------------------------------------------------
Now I want to grep inside this file (variable) another string that is also have multiple lines?

How to do it?

Thanks,
Ziv


1arryb
User

Jun 24, 2009, 7:44 AM

Post #2 of 7 (894 views)
Re: [zivsegal] grep long string [In reply to] Can't Post

Hi zivsegal,

Please post a sample of your input (you can use the upload attachment button for that) and a sample of the string you want to search for.

Cheers,

Larry


zivsegal
Novice

Jun 24, 2009, 8:06 AM

Post #3 of 7 (891 views)
Re: [1arryb] grep long string [In reply to] Can't Post

Hi,

The thing is that I have a lot of files that suppose to have header in each one of them. I also have one file that hold all the headers, one by one, each header contains many lines.
I need to parse each file and check if the header exists if not I need to insert it in the beginning of the file.
I will upload the two files.

file 1 headers -> currently have one header.
file 2 c file -> I need to find inside if the header exists.

Thanks a lot,
Ziv Segal
Attachments: gsm_conv_encoder_ga_gb.c (2.40 KB)
  headers (1.76 KB)


1arryb
User

Jun 24, 2009, 8:41 AM

Post #4 of 7 (889 views)
Re: [zivsegal] grep long string [In reply to] Can't Post

Hi ziv,

1. You say that the headers file contains a list of headers. I presume each file has a unique header? If so, how were you planning to to match a .c file with the header that belongs in it?

2. What about the case where the .c file already has a header? Is it enough that each file has a header or must existing headers be replaced?

Cheers,

Larry


zivsegal
Novice

Jun 25, 2009, 1:03 AM

Post #5 of 7 (881 views)
Re: [1arryb] grep long string [In reply to] Can't Post

Hi,
in the file that contains the headers . the syntax is
header1
func1
header2
func2
The thing is that the header & the func are multiline string.
I manege to build a hash "func->header" for this file.
now I need to search as fast as I can in a lot of c files the existing of a func. I succeed it 2. know I have to check if in those files the right header exists. the grep will not help couse it is multiline string. am I right?

Thanks,
Ziv


1arryb
User

Jun 25, 2009, 11:08 AM

Post #6 of 7 (872 views)
Re: [zivsegal] grep long string [In reply to] Can't Post

ziv,

Unless your engineers have been incredibly diciplined, you will have no control over the format, content, or position of existing headers in your source code. If that is the case, it is unlikely you will be able to devise a parse that will be safe enough to avoid manual review of every file.

Instead, I would break cleaning up the old headers and adding the new ones into separate operations. The first operation will be somewhat manual, but the second can be fully automated (given a complete and correct headers list).

For cleanup, I would recommend:

1. Figure out some string of text or regular expression that can detect an 'old-style' header.
2. Run a find command to develop a list of files containing old-style headers. For example, if an old-style header contains the string "author: ", you could go to your code root and:

Code
vim `find * -name '*.c' -exec grep -i 'author: ' -print`

And delete them interactively.

Cheers,

Larry


zivsegal
Novice

Jun 28, 2009, 12:01 AM

Post #7 of 7 (862 views)
Re: [1arryb] grep long string [In reply to] Can't Post

Thanks Larry,
I found out that if $xxx is a complex string (e.g contains mulitlines + strings that are regular expressions) I can use
if ($string =! /\Q$xxx/) so all characters in $xxx consider as text.

It help me a lot
Thanks again

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives