help understanding regex with grep & sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help understanding regex with grep & sed
# 1  
Old 10-12-2012
help understanding regex with grep & sed

I have the following line of code that works wonders. I just don't completely understand it as I am just starting to learn regex. Can you help me understand exactly what is happening here?

Code:
find .  -type f | grep -v '^\.$' | sed 's!\.\/!!'

# 2  
Old 10-12-2012
Here is what it is doing:-

Code:
find .  -type f

Finds all the files in a directory
Code:
grep -v '^\.$'

Removes files starting with . and also ending with . (since you are using -type f, this is not necessary)
Code:
sed 's!\.\/!!'

Removes first occurence of ./ from the output.
# 3  
Old 10-12-2012
Quote:
Originally Posted by bipinajith
Code:
find .  -type f

Finds all the files in a directory
That actually means find all files recursively down the tree rooted at the current directory.
# 4  
Old 10-12-2012
Thanks. I knew what
Code:
find . -type f

was for, but it was part of the line of code, so I kept it in. Thanks again for explaining the regex part!
# 5  
Old 10-13-2012
You can shorten the command to:
Code:
find .  -type f  | sed 's!./!!'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help understanding this Regex.

Hi everyone, This regex looks simple and yet it doesn't make sense how it's manipulating the output. ifconfig -a eth0 Link encap:Ethernet HWaddr 00:0c:49:c2:35:6v inet addr:192.16.1.1 Bcast:192.168.226.255 Mask:255.255.255.0 inet6 addr:... (2 Replies)
Discussion started by: xcod3r
2 Replies

2. Shell Programming and Scripting

Need Quick help on Understanding sed Regex

Hi Guys, Could you please kindly explain what exactly the below SED command will do ? I am quite confused and i assumed that, sed 's/*$/ /' 1. It will remove tab and extra spaces .. with single space. The issue is if it is removing tab then it should be Î right .. please assist.... (3 Replies)
Discussion started by: Nandy
3 Replies

3. Shell Programming and Scripting

Understanding regex behaviour when using quantifiers

# echo "Teest string" | sed 's/e*/=>replaced=</' =>replaced<=Teest string So, in the above code , sed replaces at the start. does that mean sed using the pattern e* settles to zero occurence ? Why sed was not able to replace Teest string. # echo "Teest string" | sed 's/e*//g' Tst string ... (6 Replies)
Discussion started by: chidori
6 Replies

4. Shell Programming and Scripting

Grep & sed - Output

Hi All, Facing an issue with grep & sed I have logs as below: gsc_1_20121121.log:2012-11-21 10:09:13,143 INFO - fmsspace.1 ProcessNewOrderSingleRequest: Result - ProcessNewOrderSingleBatchResultDTO - success:true,newOrderSingleBatchResults:ProcessNewOrderSingleResultDTO -... (13 Replies)
Discussion started by: irfanmemon
13 Replies

5. Shell Programming and Scripting

applescript & grep - sed command

I'm new using Unix commands in applescript. The following script you choose different folders with PDfs, get file count of PDfs on chosen folders, & write the results in text file. set target_folder to choose folder with prompt "Choose target folders containing only PDFs to count files" with... (0 Replies)
Discussion started by: nellbern
0 Replies

6. Shell Programming and Scripting

Understanding a regex

Hi, Please help me to understand the bold segments in the below regex. Both are of same type whose meaning I am looking for. find . \( -iregex './\{6,10\}./src' \) -type d -maxdepth 2 Output: ./20111210.0/src In continuation to above: sed -e 's|./\(*.\{1,3\}\).*|\1|g' Output: ... (4 Replies)
Discussion started by: vibhor_agarwali
4 Replies

7. Shell Programming and Scripting

Help Needed with grep & sed

On one of my servers, it appears that a bunch of html files got the following code added to it... I was going to try to remove this line using grep & sed... as sample grep -lr -e 'apples' *.html | xargs sed -i 's/apples/oranges/g' I can get the grep portion to work... grep "<script... (7 Replies)
Discussion started by: djlane
7 Replies

8. Shell Programming and Scripting

Regex & grep-foo

I need a way to grep -v a list of times/date from the output of postqueue -p that are a few hours old, in order to remove them with postsuper -d. Right now I have a script that is deleting the previous day of messages left in the queue, which runs once each day. I want to clean up the job and... (1 Reply)
Discussion started by: DoneWithM$
1 Replies

9. Shell Programming and Scripting

sed, grep, awk, regex -- extracting a matched substring from a file/string

Ok, I'm stumped and can't seem to find relevant info. (I'm not even sure, I might have asked something similar before.): I'm trying to use shell scripting/UNIX commands to extract URLs from a fairly large web page, with a view to ultimately wrapping this in PHP with exec() and including the... (2 Replies)
Discussion started by: ropers
2 Replies

10. Shell Programming and Scripting

grep & sed question

I'm trying to write a bash script to perform a tedious task, but I have no experience and hardly any knowledge so I've been having a rough time with it. I'm on Mac OS X, and I want a script to do the following: I have a directory that has about 200 sudirectories. In each of these directories,... (1 Reply)
Discussion started by: der Kopf
1 Replies
Login or Register to Ask a Question