Regex/sed - matching any char,space,underscore between : and /

trying to remove the portion in red:

Data:

mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql
mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly.sql

output to be:

mds_ar/bin/uedw92wp.ksh: wkly.sql
mds_ar/bin/uedw92wp.ksh: wkly.sql

SED i'm trying to use:

sed 's/:[$a-zA-Z_ ]+\//: /g' input_file.dat > output_file.dat

from what i understand of Regex i've coded means:

  1. look for : followed by any lower/upper case character, including $ and spaces followed by / and replace with :space

What am i missing?

echo 'mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql' | sed 's#^\([^:][^:]*\):[^/][^/]*/\(.*\)#\1: \2#'
OR
echo 'mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql' | sed 's#:[^/][^/]*/#: #'

Your code is correct but for one char:

sed 's/:[$a-zA-Z_ ]\+\//: /g' input_file.dat > output_file.dat

sed has the strange thing that it needs it qualifiers escaped, otherwise it treads it as characters.

This seems to work

 sed 's/:[ $A-Za-z]\//:/'

echo "mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql
mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly.sql" |
  sed 's/:[ $A-Za-z]\//:/'
csadev:/home/jmcnama> t.sh
mds_ar/bin/uedw92wp.ksh:wkly.sql
mds_ar/bin/uedw92wp.ksh:wkly.sql

Doesn't work on Solaris - you're looking for ONE char between ':' and '/':

$ echo 'mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql' | sed 's/:[ $A-Za-z]\//:/'
mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql

Yes, the + means more characters in the same character class.

Right, but you don't have it :wink:
BTW, not all sed-s support '+' - Solaris' version doesn't - have to simulate it with '[c][c]*'.

I'm on AIX

i've put the following into a file and ran it and got the same correct results as Jim below

 
echo "mds_ar/bin/uedw92wp.ksh: $AI_SQL/mthly.sql
mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly.sql" |
  sed 's/:[ $A-Za-z]\//:/'

But when i do the following, it's not working: :confused: :confused:

My input data file:

mds_ar/bin/uedw92wp.ksh:$AI_SQL/wkly_prtl_nb.sql
mds_ar/bin/uedw92wp.ksh:$AI_SQL/wkly_prtl_nb_st.sql
mds_ar/bin/uedw92wp.ksh:$AI_SQL/wkly.sql
mds_ar/bin/uedw92wp.ksh:sed "s/schemaname/${Gmdsschema}/g" $EDW_TMP/wkly.sql
mds_ar/bin/uedw92wp.ksh:sed "s/schemaname/${Gmdsschema}/g" $EDW_TMP/wkly_tmp.sql
mds_ar/bin/uedw92wp.ksh:sed "s/dw_evnt_acntg_dt/${Vdw_evnt_acntg_dt}/g" $EDW_TMP/wkly_tmp.sql
mds_ar/bin/uedw92wp.ksh:cat $AI_SQL/mnthly_mqt.sql

Code run against input file:

 
sed 's/:/: /g' input_file.dat | awk '{print($1,$NF)}' | sed 's/:[ $A-Za-z]\//:/'

Results i'm getting:

mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly_prtl_nb.sql
mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly_prtl_nb_st.sql
mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql
mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly.sql
mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly_tmp.sql
mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly_tmp.sql
mds_ar/bin/uedw92wp.ksh: $AI_SQL/mnthly_mqt.sql

So now i'm confused.... how could it have worked on the script from Jim and not mine...

could you explain the syntax?

[^/]* means zero to many of any charaters other then /

---- but why have [^/] that twice?

and why didn't what i have work?

:[$a-zA-Z_ ]+\/

doesn't the above signify a semi-colum followed by any number of (alpha-charaters OR dollar signs OR underscores OR spaces ) followed by the slash / :confused:

thanks... i'm trying to understand the why, instead of just being a copying monkey :smiley:

correct

As I noted before... not all versions of 'sed' support the '+', e.g. Solaris' "sed" does not. So in order to 'simulate' the meaning of '+' (one or more occurrences of the preceding regex, one can do it as I did.
In order words,
[^/] - exactly one occurrence of any single char, but '/'
[^/]* - zero or more occurrences of any single char, but '/'

The above two combined mean: one or MORE occurrence.
Hope my verbiage is clear.

Most likely because of the above - your 'sed' does not understand/support '+'.

no, the above means: a semi-column followed by ONE OR MORE of (alpha-charaters OR dollar signs OR underscores OR spaces ) followed by the slash /
Once again, if your 'sed' supports '+'

this is extremely commendable!!!

Thanks again for you help and patience...