I am trying to write my gsub regex to replace a bunch of special characters with spaces, so i can split it to an array and look at each word independently.
However, my regex skills are slightly lacking and I appear to be missing a quote or something here.
I am trying to replace the following characters \/;:'"`()| with a space.
When i run this piece of the code i get the following error.
line 240: syntax error at line 289: `)' unexpected
Caution: This might be a very naive one since am a beginner here
47 stands for '
Quote:
..its a octal value
That almost works. You don't need (or want) the asterisk in a call to gsub(). It matches every string of zero or more matches, which in this case effectively adds a space before any of the characters in the input that aren't in the list. You have several backslash characters escaping characters that aren't special inside a bracket expression, but they shouldn't hurt anything. Also, if the last arg to gsub() is left off, it uses $0 as a default.
The following line works:
Note, however, that this solution won't work on a system with EBCDIC as the codeset for the C Locale. (I think IBM still supports systems like this.) On a system using EBCDIC, you'd need to use \175 instead of \47. If you want to put this in an awk program file (where the script won't have quote processing performed by the shell before awk sees it, the following line should work:
script:
will work without codeset dependencies.
Last edited by vgersh99; 08-21-2012 at 03:58 PM..
Reason: fixed code tags
These 2 Users Gave Thanks to Don Cragun For This Post:
Thanks for the tips....I have it working on my HP boxes and Redhat boxes now.
I am running this as part of a KSH script so i still need the quote processing.
Here is the current code (i added a few more symbols).
Im not sure why but for whatever reason Solaris does not like this. I keep getting the following error.
Quote:
/usr/xpg4/bin/awk: line 8 (NR=1): /[)(=;:/'`"|.$-@%]/: invalid endpoint in range
Thanks for the tips....I have it working on my HP boxes and Redhat boxes now.
I am running this as part of a KSH script so i still need the quote processing.
Here is the current code (i added a few more symbols).
Im not sure why but for whatever reason Solaris does not like this. I keep getting the following error.
Just to be sure I understand what you're saying, you have a ksh shell script that at some point contains something like:
and you have chosen to use the call to gsub() shown above rather than the suggestion I made in an earlier post:
because you now also want to change the characters <period>, <dollar-sign>, <hyphen>, <at-sign>, and <percent-sign> to a <space> in addition to the characters you were changing before. Is that correct?
Note that having $-@ in a bracket expression in the 1st argument to gsub after quote removal is a range expression matching <dollar-sign>, <at-sign> and everything that comes between them in your current locale definition. In the POSIX locale, that should match the following characters
not just the $, -, and @.
I put together an input file to use to test various calls to gsub:
in.gsubspecial:
and used the following commands in a shell script to test out three sample
gsub() calls I produced and the gsub call you have above.
When I run this script, I get the following output:
I don't know why your gsub wouldn't work with /usr/xpg4/bin/awk on Solaris 10. (Is there any chance that you're using a Locale with a non-standard setting for the LC_COLLATE category? Are you sure that you are using exactly the same script on Solaris 10 that you're using on the other systems? Having another single-quote anywhere in your awk script [even in a comment] could greatly change the behavior.) I do see that your gsub() call fails to change a backslash character into a space. If you intended to use the $-@ as a range expression, we can get rid of several character in the matching list expression that are not only listed individually, but are also included in the range expression (including the single-quote).
Hopefully, this will give you something you can adapt to something you can use.
I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works:
LOCAL_CONFIG
#
Kcheckaddress regex -a@MATCH
+<@+?\.++?\.(us|info|to|br|bid|cn|ru)
LOCAL_RULESETS
SLocal_check_mail
# check address against various regex... (0 Replies)
I am not a big expert in regex and have just little understanding of that language.
Could you help me to understand the regular Perl expression:
^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{
------
This is regex to select functions from a C/C++ source and defined in... (2 Replies)
I have a number of files that I pass through awk/gsub.
I believe to have found a working regex and on 'test bed' sites it matches, however within gsub it does not.
Examples:
Initial data:
/Volumes/Daniel/Public/Drop Box/_Hellsing_Ultimate_OVA_-_10_.mkv
gsub & regex:
gsub("\]+\]",""
... (4 Replies)
Hi, I want to print the first column with original value and without any double quotes
The output should look like
<original column>|<column without quotes>
$ cat a.txt
"20121023","19301229712","100397"
"20121023","19361629712","100778"
"20121030A","19361630412","100838"... (3 Replies)
Hello,
i'm searching for a solution to this problem.
I have 2 files, the first one is like:
<HTML>
<HEAD>
<TITLE>{$String1}</TITLE>
</HEAD>
<BODY>
<P>{$String2}</P>
</BODY>
</HTML>and the other one:
{$String1}; french
{$String2}; italian
{$String3}; english
...
{$StringN};
I... (3 Replies)
I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly:
if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Hello,
I have a variable that displays the following results from a JVM....
1602100K->1578435K
I would like to collect the value of 1578435 which is the value after a garbage collection. I've tried the following command but it looks like I can't get the > to work. Any suggestions as... (4 Replies)
Hello
I have problem with reg-expr and function gsub();
File that I want to preprocess look like this:
int table ;
printf(" variable : ", variable) ;
Using nawk I try something like this:
for ( .... )
{
line = $0
reg_expr = "\.\=]*" "" variable "" "\.\=]*" ;
gsub( reg_expr... (1 Reply)