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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regex/sed - matching any char,space,underscore between : and /
# 8  
Old 02-18-2009
I'm on AIX
# 9  
Old 02-18-2009
i've put the following into a file and ran it and got the same correct results as Jim below

Code:
 
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: Smilie Smilie


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:


Code:
 
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...
# 10  
Old 02-18-2009
Thanks.... but trying to understand...

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 / Smilie

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

Quote:
Originally Posted by vgersh99
Code:
 
echo 'mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql' | sed 's#:[^/][^/]*/#: #'

# 11  
Old 02-18-2009
Quote:
Originally Posted by danmauer
could you explain the syntax?

[^/]* means zero to many of any characters other then /
correct
Quote:
Originally Posted by danmauer

---- but why have [^/] that twice?
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.
Quote:
Originally Posted by danmauer
and why didn't what i have work?

:[$a-zA-Z_ ]+\/
Most likely because of the above - your 'sed' does not understand/support '+'.
Quote:
Originally Posted by danmauer

doesn't the above signify a semi-column followed by any number of (alpha-charaters OR dollar signs OR underscores OR spaces ) followed by the slash / Smilie
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 '+'
Quote:
Originally Posted by danmauer
thanks... i'm trying to understand the why, instead of just being a copying monkey Smilie
this is extremely commendable!!!
# 12  
Old 02-18-2009
Thanks again for you help and patience...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed: -e expression #1, char 20: unterminated address regex

I am trying to add word in last of particular line. the same command syntex is running on prompt. but in bash script give error."sed: -e expression #1, char 20: unterminated address regex" Please help. for i in `cat servername`; do ssh -q -t root@$i sed -i '/simple_allow_groups =/s/$/,... (4 Replies)
Discussion started by: yash_message
4 Replies

2. Shell Programming and Scripting

Replace a space with underscore in a file

i have a file with following data. { EqName "Tan 1" .... .... } { EqName "Sin 2" ... ... } I have to replace the value of EqName to Tan_1 and Sin_2 in file.Can i use sed or awk ? cat file|grep EqName|awk '{print $2 $3}'|sed -i 's//_/g' I tried with this but it... (2 Replies)
Discussion started by: Jag02
2 Replies

3. Shell Programming and Scripting

Sed: -e expression #1, char 16: unterminated address regex

I am trying to grep for a particular text (Do action on cell BL330) in a text file(sample.gz) which is searched in the content filtered by date+timestamp (2016-09-14 01:09:56,796 to 2016-09-15 04:10:29,719) on a remote machine and finally write the output into a output file on a local machine. ... (23 Replies)
Discussion started by: rbadveti
23 Replies

4. Shell Programming and Scripting

Awk, function of underscore char.

Hello Friends, I would appreciate so much if you could explain how the underscores works at the following code? Sorry if it sounds a bit novice question. awk -F',' 'NR==FNR{_=1;next}!_{print}' exclude infile KR, Eagle (6 Replies)
Discussion started by: EAGL€
6 Replies

5. Shell Programming and Scripting

SED: Pattern repitition regex matching

Fairly straightforward, but I'm having an awful time getting what I thought was a simple regex to work. I'll give the command I was playing with, and I'm aware why this one doesn't work (the 1,3 is off the A-Z, not the whole expression), I just don't know what the fix is: Actual Output(s): $... (5 Replies)
Discussion started by: Vryali
5 Replies

6. Shell Programming and Scripting

Using of gsub function in AWK to replace space by underscore

I must design a UNIX script to monitor files whose size is over a threshold of 5 MB in a specific UNIX directory I meet a problem during the for loop in my script. Some file names contain spaces. ls -lrt | awk '$5>=5000000 && length($8)==5 {gsub(/ /,"_",$9); print};' -rw-r--r-- 1 was61 ... (2 Replies)
Discussion started by: Scofield38
2 Replies

7. UNIX for Dummies Questions & Answers

blank space in regex pattern using sed

why does sed 's/.* //' show the last word in a line and sed 's/ .*//' show the first word in a line? How is that blank space before or after the ".*" being interpreted in the regex? i would think the first example would delete the first word and the next example would delete the second... (1 Reply)
Discussion started by: glev2005
1 Replies

8. UNIX for Advanced & Expert Users

Sed - add text to start of line if 1st char anything but space

Problem: I have a lot of files, the files first line should always have 4 spaces before any text. Occasionally some of the files will miss the leading spaces and it's a problem. This is only in the first line. So if there are 4 spaces then text, do nothing. If there are not 4 spaces, add 4... (2 Replies)
Discussion started by: Vryali
2 Replies

9. UNIX for Dummies Questions & Answers

Replacing underscore with white space after comma.

Hi all, I'm hoping you can help.. I've used this forum a couple of times and I am back again now i've moved onto something more complex (for me!) I have some data which looks like: "AL1_1,AL1_1," "AL1_1.AL1_1A.AL1_1AE,AL1_1AE," "AL1_1.AL1_1A.AL1_1AG,AL1_1AG," "AL1_1.AL1_1A.AL1_1AJ,AL1_1AJ,"... (10 Replies)
Discussion started by: gman
10 Replies

10. Shell Programming and Scripting

sed - print only matching regex

Hi folks, Lets say I have the following text file: name, lastname, 1234, name.lastname@test.com name1, lastname1, name2.lastname2@test.com, 2345 name, 3456, lastname, name3.lastname3@test.com 4567, name, lastname, name4.lastname4@test.com I now need the following output: 1234... (5 Replies)
Discussion started by: domi55
5 Replies
Login or Register to Ask a Question