Sponsored Content
Full Discussion: GSUB/Regex Help
Top Forums Shell Programming and Scripting GSUB/Regex Help Post 302689529 by Don Cragun on Tuesday 21st of August 2012 02:51:52 PM
Old 08-21-2012
Quote:
Originally Posted by msabhi
Can you please try this :

Code:
awk '{gsub(/[\|\(\)\\\/\;\:\47\`\"]*/," ",$0);}1' input_file

Caution: This might be a very naive one since am a beginner hereSmilie
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:
Code:
awk '{gsub(/[|()\\\/;:\47`"]/," ");}1' input_file

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:
Code:
 {gsub(/[|()\\\/;:'`"]/," ");print}

Code:
awk -f script input_file

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:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gsub and nawk

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)
Discussion started by: scotty_123
1 Replies

2. Shell Programming and Scripting

Help with AWK and gsub

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)
Discussion started by: npolite
4 Replies

3. Shell Programming and Scripting

Converting perl regex to sed regex

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)
Discussion started by: suntzu
1 Replies

4. Shell Programming and Scripting

How to use gsub and array

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)
Discussion started by: heaven25
3 Replies

5. UNIX for Dummies Questions & Answers

awk gsub(): general regex

%%%%% (9 Replies)
Discussion started by: lucasvs
9 Replies

6. Shell Programming and Scripting

awk gsub

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)
Discussion started by: ysrini
3 Replies

7. UNIX for Dummies Questions & Answers

Gsub regex not working

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)
Discussion started by: unknownn
4 Replies

8. Shell Programming and Scripting

Perl, RegEx - Help me to understand the regex!

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)
Discussion started by: alex_5161
2 Replies

9. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

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)
Discussion started by: RobbieTheK
0 Replies
All times are GMT -4. The time now is 02:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy