![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need a regular expression | tony3101 | Shell Programming and Scripting | 4 | 06-05-2008 03:13 AM |
| regular expression and awk | nickg | UNIX for Dummies Questions & Answers | 2 | 08-16-2007 05:23 PM |
| regular expression...help!! | andy2000 | UNIX for Dummies Questions & Answers | 6 | 07-18-2007 05:10 PM |
| help in regular expression | Rakesh Ranjan | High Level Programming | 5 | 10-25-2006 01:00 PM |
| Regular Expression + Aritmetical Expression | Z0mby | Shell Programming and Scripting | 2 | 05-21-2002 10:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
regular expression (.*?)
hi all,
i have a text file with below content ............................... ............................... ............................... ............................... %%Page: (4) 4 %%PageBoundingBox: 34 -30 584 831 %%BeginPageSetup %%BeginFeature: *PageSize A4 595 842 SetPageSize %%EndFeature %%BeginFeature: *Duplex None false false SetDuplexMode %%EndFeature %%EndPageSetup GS ......................... ................................ .......................................... i want to add some lines after GS so in perl i tried this $data = ~s/%%Page: (4) 4(.*?)GS/%%Page: (4) 4 $1 GS setlinewidth \n 25 110 moveto \n 75 110 lineto/g; where $data holds file content. this is working fine and the output is ............................... ............................... ............................... ............................... %%Page: (4) 4 %%PageBoundingBox: 34 -30 584 831 %%BeginPageSetup %%BeginFeature: *PageSize A4 595 842 SetPageSize %%EndFeature %%BeginFeature: *Duplex None false false SetDuplexMode %%EndFeature %%EndPageSetup GS setlinewidth 25 110 moveto 75 110 lineto ......................... ................................ .......................................... but when i tried this with perl command line it is not working perl -p -i -e 's/%%Page: (4) 4(.*?)GS/%%Page: (4) 4 $1 GS setlinewidth \n 25 110 moveto \n 75 110 lineto/g' FILENAME Kindly suggest me the solution(in sed/awk/perl etc) Thanks in advance uttam hoode |
|
||||
|
You need to add -0777 to the Perl command line to make it read the whole file in one go, rather than one line at a time. You also need to add an /s modifier to the regex substitution to make dot match a newline (you ought to have needed this in your proof of concept on $data, too).
|
|
||||
|
hi all,
thanks for the reply all the solutions are working fine(after using -0777). actully i am calling above commands in perl script and i forgot to escape speacial charactes (% $ \n etc). #!/usr/bin/perl ...................... ......................... `perl -0777 -p -i -e 's/\%\%Page: \\(4\\) 4\\(\\.\\*\\?\\)GS/\\%\\%Page: \\(4\\) 4 \$1 GS setlinewidth \\n 25 110 moveto \\n 75 110 lineto/s' filename`; .................. ................ Thanks and Regards, uttam hoode |
![]() |
| Bookmarks |
| Tags |
| perl, perl regex, regex |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|