Multi platform script perl or awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multi platform script perl or awk
# 8  
Old 10-05-2012
Quote:
Originally Posted by wakatana
What I am doing wrong
You are providing the regular expression as a string literal. Strings literals have to be parsed. The string parser has its own set of escape sequences. The \\ sequences that you intend for the regular expression are being interpreted by the string parser first, and for each such pair it emits a single backslash. You can confirm this by printing the variable's value.

At a later time, the string-valued variable is used where a regular expression is expected. AWK then passes this string to the regular expression parser for compilation. At this point, the error occurs.

You have two choices. You can double the number of backslases or you can specify the regular expression using a regular expression literal instead of a string literal (/pattern/ instead of "pattern").

For more info, see Computed Regexps - The GNU Awk User's Guide (this applies to all awk implementations, not just gawk).

Regards,
Alister

---------- Post updated at 11:58 AM ---------- Previous update was at 11:53 AM ----------

Quote:
Originally Posted by Chubler_XL
A slight change to your original awk should get the job done:

Code:
awk 'BEGIN {musr="[(]-,username,[^)]+.co.uk[)]\\\\?"} $0~musr' netgroup

Two of the \ chars are stripped by the shell, leaving \\ for awk
Since they occur within single quotes, the shell isn't consuming any backslashes. As I said above, it's awk's string parser.

An improved version of your suggestion:
Code:
awk '$0 ~ /pattern_with_half_the_backslashes/' netgroup

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 9  
Old 10-06-2012
Thanks guys I know something was consuming the additional backslashes.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Solaris

Application not working in multi core platform

Hi, I have a multiprocess C application (used POSIX library for threads and fork() & exec for creating process) of millions of LOC. 1. Which works fine in single processor machine. 2. Which works fine in multicore machine only if one core is enabled. Problem is, which results an undefined... (2 Replies)
Discussion started by: sreejesh
2 Replies

2. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

3. UNIX for Advanced & Expert Users

Multi-platform Centralized Patch Management

We have a mix of AIX, HP-UX, Linux (RHEL and SLES), and Solaris in our environment. Currently we have seperate patch management systems for each platform (NIM, SD, Spacewalk, etc), but have started looking for a centralized patch management solution that would work for most, if not all, of our... (0 Replies)
Discussion started by: kknigga
0 Replies

4. Programming

Multi-platform includes?

I know that <cstudio> can also be <stdio> and can be written different ways on Linux then with windows. I've see some code doing a IFDEF __APPLE__ (I'm guessing, if compiled on a mac do whats between this) Is there one for Linux/Window? (3 Replies)
Discussion started by: james2432
3 Replies

5. UNIX for Dummies Questions & Answers

running a Perl script on HPUX platform

Hi, I wish to execute a simple perl script to pass unix commands on a HPUX platform, retrieve the result and filter through the text to determine outcomes x,y and z. I am developing the code on my windows system. I initially wrote the code to issue UNIX commands line by line, however i soon... (1 Reply)
Discussion started by: mmetcalfe
1 Replies
Login or Register to Ask a Question