[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash, Sed and Find

From: Matt Venn
Subject: Bash, Sed and Find
Date: Thu, 5 Apr 2001 15:45:35 +0100
User-agent: slrn/ (Linux)

First, let me apologise for the possible off topic. I don't know where
to start trying to find a solution to this problem, so I thought I'd
start with Bash.

The problem arises when using a complicated find statement, involving
-exec ing sed.

1/- cd /tmp; mkdir new; touch new/1
2/- find new/ -type f \
-exec echo $( echo {} | sed -e 's#\(.*\)#sed->\1<#' ) \;
3/- find new/ -type f -exec echo $( echo {} | sed -e 's#new/##' ) \;
4/- echo "new/1" | sed -e 's#new/##'

1/- moves to /tmp, creates /tmp/new/1
2/- shows that sed is getting the whole path of new/1 - prints
3/- shows that simple regexes fail - prints 'new/1', should print '1'
4/- shows that in isolation the same simple regex works, prints '1'.

Can someone tell me whether this is a bash related problem, or should I
look at Find and Sed?

One thing in particular that I don't understand is that I thought $()
was evaluated before the rest of the command. If this is the case, how
does the {} inside the $() get interpolated?

But if I do:

find new/ -type f -exec echo $( echo {} | od -c ) \;

I get:

0000000 { } \n 0000003

So it looks like in this case its not being interpolated... 

Thanks for any help, Matt

$A='A';while(print+($A.=(grep{($A=~/(...).{78}$/)[0]eq$_}"  A A A  "
=~m{(...)}g)?"A":" ")=~/([ A])$/){if(!(++$l%80)){print"\n";sleep 1}}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]