Visit Our UNIX and Linux User Community

Help with Reg. Expression

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with Reg. Expression
# 1  
Old 07-16-2007
Computer Help with Reg. Expression

I need help with this:
Can any one tell me what does these below mean:

1. "\(.\).*") != '/'

2. sed 's+^\./++;s+/.*++'

3. sed "s+${f}/+ +

Thanks in advance
# 2  
Old 07-16-2007
1. "\(.\).*") != '/'
It does not conform with a known regular expression.
I don't know what it means.
2. sed 's+^\./++;s+/.*++'
The above 'sed' has two replacement commands:
a) s+^\./++
Removes './' from the beginning of each line/string.

b) s+/.*++
Removes anything that starts with '/' from each line/string.
3. sed "s+${f}/+ +
You are missing a double quote (") at the end -- it should be:
sed "s+${f}/+ +"
It replaces the content of variable 'f' followed by one '/' with one space.
# 3  
Old 07-16-2007
I think Shell did a nice job explaining stuff, but since I went to all the trouble of writing this post... before he beat me to it Smilie ... I will post anyway

1 - The first one makes no sense, cause it has no context... it looks to me like it was part of an if statement or something like that, in which case it was probably more like this:

if m/\(.\).*/ != '/'

in which case it still makes no sense, cause you are asking whether "(oneCharacter)anyNumberOfCharacters" = "/"
Which quite obviously it never would

2 - Sed is short for "String Editor", and allows you to manipulate strings, so the 's+++' that you see is really just the same as 's~~~' or 's///' and means:

"Search for the thing in between the first two delimiters (+ for you) and replace it with what is between the second two delimiters... but only do it the first time you find it, and never again"

next regEx knowledge for you is that ^ represents the absolute beginning of a string and $ the absolute end... also, since sed is technically running everything in between the ticks (') as a script, you can make multiple search/replace calls to the same info, and they are run sequentially, each applying changes to the string that was passed to them...

SO... the second one is looking for a period followed by a forward slash, and removing it (replacing with nothing)... then it passes that new string into the second half which searches for a forward slash followed by any number of single characters (absolutely anything basically) and removes the stuff...

so basically a use for the second one would be to get a list of directory names from a list... the only problem is that you never give any input to sed, so it will never really do anything... so try going to a shell and doing this:

ls -R | sed 's+^\./++;s+/.*++'

Not that this does anything useful, but you can see what it does compared to the ls -R command without the pipe to sed...

3 - Again, this is just a search/replace, this time replacing with a space... but the difference is that this is looking for a shell variable named 'f', and it is going to put the content of 'f' in that search... so if 'f' is 'Fred' then we are going to search for 'Fred' and replace it with ' '
# 4  
Old 07-16-2007
Originally Posted by jjinno
sed is short for "String Editor"
Actually it's "stream(s) editor"
# 5  
Old 07-16-2007

Sorry folks;
the first one that you mentioned it didn't mean any thing, it was part of this:

PROG=$(basename ${DZERO})
while [ -h ${DZERO} ]; do
DZERO=$(ls -l ${DZERO} | awk '{print $NF}')
PDIR=$(dirname ${DZERO})
if [ ${PDIR} = '.' ]; then
elif [ $(expr ${PDIR} : "\(.\).*") != '/'[/B] ]; then
# 6  
Old 07-16-2007
For the third one, it's a part of this:

for f in ${files}
echo " ${f}"
find ${f} -name '*.*' -print | sed "s+${f}/+ +"
rm -ri ${f}
n=$((${n} + 1))
# 7  
Old 07-16-2007
From what I can gather, the third one looks like you want a verbose recursive removal script...only I am not so sure about the 'find ${f}' part...

Here is the deal (I think)...

The ${files} is weird, cause if you are actually looping through file names, then the 'find ${f}' line isnt going to find much unless your directories are named the same as your files, and even then, it is only going to match within the current directory and if it does that, then the sed is pointless, cause it is intended to strip paths...

So, if the '${files}' actually was intended to be a "loop through directory names", then it makes a little more sense. In this case, each 'find ${f}' line would produce a list of all files in all subdirectories under the directory specified by '${f}' which comes from the list '${files}'. As each line comes out, the first occurrence of that directory name would be printed as its own line and removed from all subsequent echo's...

So basically this script prints out everything under a directory that you "theoretically" want to delete, and asks you whether or not you want to delete every file therein... oh, and it keeps a count... not that that seems to matter, since you do nothing with it.

I had a friend once that aliased a script like this to his "rm -rf" command so that if he stupidly ran an "rm -rf /" he would get some 3 million lines of echoed files, and realize that he was dumb...

Hope this helps.

Previous Thread | Next Thread
Test Your Knowledge in Computers #462
Difficulty: Medium
NTPv4 introduced a 256-bit date format: 128 bits for the second and 128 bits for the fractional-second.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

REG Expression

Need your help in creating regular expression for particular set. let say I have given two dates 20130623 to 20140625. I need to create regular for the dates which fall in between above two dates. (4 Replies)
Discussion started by: gvkumar25
4 Replies

2. Shell Programming and Scripting

Confusion with Reg expression

I want to make a REG Expression to validate the directory. my dirsample is below: /abc/abc/abc abc/abc/abc abc/abc/abc/ /abc/a bc/abc /a bc/abc/abc /abc/abc/a bc / abc/abc/abc /abc/ abc/abc /abc/.abc /.abc/abc / // /abc /.abc And my code is below: grep -E '^\/(+\/?)+$' dirsample (4 Replies)
Discussion started by: franksunnn
4 Replies

3. Shell Programming and Scripting

reg expression in perl

how to uniquely match each of the words seperated by / in perl ${REP_PATH}/FUNCTIONAL/wide1c_1.0V/max/qor.rpt (5 Replies)
Discussion started by: dll_fpga
5 Replies

4. Shell Programming and Scripting

reg expression in perl

./ -f ${REP_PATH}/FUNCTIONAL/wide1c_1.0V/max/qor.rpt -o ${REP_PATH}/FUNCTIONAL/GEN2_wide1c_1.0V_max.csv where is as below...i need to check whether max or min is coming in the argument to the script to do this? ${REP_PATH}/FUNCTIONAL/wide1c_1.0V/max/qor.rpt ... (0 Replies)
Discussion started by: dll_fpga
0 Replies

5. Shell Programming and Scripting

Reg expression

Please let me understand this reg expression (\s+')(.*)('\s+)(.)(.*)(\/.*)/) i have doubt in the below 2.I'm not understanding why back-tick used? (\s+') and ('\s+) (2 Replies)
Discussion started by: dll_fpga
2 Replies

6. Shell Programming and Scripting

awk reg expression

Hello, I have thousand of messages (HL7), I want to use awk to extract only the ones that have a particular value in pv1.18 Each record in the file is the whole HL7 message, ie. when I print $0 I get the whole message MSH EVN PID etc. ,there is an x0d between the segments. I would like to use a... (3 Replies)
Discussion started by: gio001
3 Replies

7. Shell Programming and Scripting

Python (startswith) reg expression

Hello together, Yesterday I have recieved the script in the forum which works well. This script should insert in the previous line, the line that starts with ";". I'd like this process to recur after any arbitrary sign unless there's a number as a sign at the beginning of a line. Actual... (14 Replies)
Discussion started by: research3
14 Replies

8. Shell Programming and Scripting

Reg expression For

HI system.sysUpTime.0 : Timeticks: (1519411311) 175 days, 20:35:13.11 From the above output i need only 175days in a perl script.. Please Help (2 Replies)
Discussion started by: Harikrishna
2 Replies

9. Shell Programming and Scripting

perl reg expression

I have regular expression like this ( replace + with \+) ($mod_server) = ($server =~ /\+/\\+/g); the above is failing with error . what's wrong with it . Thanks (1 Reply)
Discussion started by: talashil
1 Replies

10. Shell Programming and Scripting

Awk - Using a Shell Variable in the Reg Expression

Hi all, I have a shell variable $test1 that holds a value derived from some other processing. What I need to do is use that $test1 as the input to a awk regular expression: nawk -F"," -v tester=$test1 ' /tester/{ print $0 } ' $inputFile So what I have is tester... (6 Replies)
Discussion started by: not4google
6 Replies

Featured Tech Videos