awk gsub(): general regex

Thread Tools Search this Thread
# 1  
awk gsub(): general regex


Last edited by lucasvs; 05-01-2012 at 07:15 AM..
# 2  
Try regular sub (gsub not necessary) with /[^0-9]*$/ and replace with "."
**edit** this is incorrect, since string to delete may also contain numbers

Last edited by Scrutinizer; 04-02-2012 at 07:33 AM..
# 3  
awk '{print gensub (/(.+[0-9]+[^0-9]+[0-9]+).*\./,"\\1.","g")}'

sed  's/\(.\+[0-9]\+[^0-9]\+[0-9]\+\).*\./\1./g'

(GNU awk/sed)

Last edited by CarloM; 04-02-2012 at 07:49 AM.. Reason: Keep the second number
# 4  
awk '{$3=$3"."}NF=3'

# 5  

Last edited by lucasvs; 05-01-2012 at 07:15 AM..
# 6  
Well, they worked on your original example Smilie.

Carlo@CRM-MT4 ~
$ echo "AAAA 1 2 f45 iop 234-RT.; AAAA 123 456 gf kuygb 2iuygb.; AAAA 678 89 wer4k lh8." |
> awk  '{print gensub (/([[:alnum:]]+[[:blank:]]+[[:digit:]]+[[:blank:]]+[[:digit:]]+)[^.;]*/,"\\1","g")}'
AAAA 1 2.; AAAA 123 456.; AAAA 678 89.

Carlo@CRM-MT4 ~
$ echo "AAAA 1 2 f45 iop 234-RT.; AAAA 123 456 gf kuygb 2iuygb.; AAAA 678 89 wer4k lh8." |
>  sed  's/\([[:alnum:]]\+[[:blank:]]\+[[:digit:]]\+[[:blank:]]\+[[:digit:]]\+\)[^.;]*/\1/g'
AAAA 1 2.; AAAA 123 456.; AAAA 678 89.

Last edited by CarloM; 04-03-2012 at 05:31 AM..
This User Gave Thanks to CarloM For This Post:
# 7  

Last edited by lucasvs; 05-01-2012 at 07:16 AM..

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #1006
Difficulty: Medium
In calculus and most other branches of mathematics beyond practical geometry, angles are universally measured in degrees.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gsub function in awk

Hello, I had some difficulty to understand the gsub function and maybe the regex in this script to remove all the punctuations: awk 'gsub(//, " ", $0)' text.txtFile text.txt: This is a test for gsub I typed this random text file which contains punctuation like ,.;!'"?/\ etc. The script... (6 Replies)
Discussion started by: yifangt
6 Replies

2. UNIX for Dummies Questions & Answers

awk gsub with variables

Hello, I'm trying to substitute a string with leading zero for all the records except the trailer record using awk command and with variables. The input file test_med1.txt has data like below 1234ABC...........................9200............LF... (2 Replies)
Discussion started by: somu_june
2 Replies

3. 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

4. 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

5. Shell Programming and Scripting

GSUB/Regex Help

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... (6 Replies)
Discussion started by: nitrobass24
6 Replies

6. Shell Programming and Scripting

Awk Gsub Query

Hi, Can some one please explain the following line please throw some light on the ones marked in red awk '{print $9}' ${FTP_LOG} | awk -v start=${START_DATE} 'BEGIN { FS = "." } { old_line1=$0; gsub(/\-/,""); if ( $3 >= start ) print old_line1 }' | awk -v end=${END_DATE} 'BEGIN { FS="." } {... (3 Replies)
Discussion started by: crosairs
3 Replies

7. Shell Programming and Scripting

awk gsub

Hi all I want to do a simple substitution in awk but I am getting unexpected output. My function accepts a time and then prints out a validation message if the time is valid. However some times may include a : and i want to strip this out if it exists before i get to the validation. I have shown... (4 Replies)
Discussion started by: pxy2d1
4 Replies

8. 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

9. Shell Programming and Scripting

use var in gsub of awk

Hi all, This problem has cost me half a day, and i still do not know how to do. Any help will be appreciated. Thanks advance. I want to use a variable as the first parameters of gsub function of awk. Example: { ... arri]=gsub(i,tolower(i),$1) (which should be ambraced by //) ... } (1 Reply)
Discussion started by: summer_cherry
1 Replies

Featured Tech Videos