jeudi 2 août 2018

Conditional gsub action

According to this answer, I am trying to reproduce a conditional statement where, in the event of a match, a substitusion occurs (it matches dates). If no match happens, the line is printed as it is.

#!/bin/bash

cleaner(){
        ./date_remove.awk $1 
}

cleaner $1 > "out"

where 'date_remove.awk' is

#! /usr/bin/awk -f

date = /(^|[^[:alpha:]])[[:digit:]]{2}[[:space:]]{1,}[[:alpha:]]{3,8}[[:space:]]{1,}[[:digit:]]{4}([^[:alpha:]]|$)/ {gsub(date, "")} !date {print}

At this point the substitution does not happens. 'gsub' should return only the matched phrases, but it does not return anything, actually. Just unmatched phrases are printed correctly. At this point, I am pretty sure is a problem of syntax, but I cannot figure out where.

Aucun commentaire:

Enregistrer un commentaire