Mailing List Archive


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

Re: [tlug] grep, sed, and cat - oh my!



On 2010-09-16 at 11:50:22, Dave M G wrote:
>For combining the Javascript files in step 2, they are in
>subdirectories. I came across a command which supposedly might do the
>trick:
>ls -1R|grep :$|sed 's/:$//g'| awk '{print $1"/*"}'|xargs cat > all.js

How about something like this:

find $DIR -type f -name '*.js' -exec cat {} \; > all.js

Replace $DIR with whatever directory your files are in. Will that work 
for you?

>For step 4, editing the HTML files, I think I need to run the
>following command:
>sed 's/.*<script type="text/javascript" charset="utf-8"
>src="javascript/includes.js"></script>.*/<script
>type="text/javascript" charset="utf-8" src="all-min.js"></script>/g'

I can see one obvious problem. The sed command you are running is s///. 
But the arguments to that command contain slash characters that are not 
escaped. I'll make an assumption as to which slashes should *not* be 
escaped, and escape the rest to show what i mean. Try this:

sed 's/.*<script type="text\/javascript" charset="utf-8"
src="javascript\/includes.js"><\/script>.*/<script
type="text\/javascript" charset="utf-8" src="all-min.js"><\/script>/g'

>And in either case, can I tweak it to only act on files with a ".html"
>extension?

Usually you have to specify what files sed is to operate on. Only feed 
it files with a .html extension, and it will only operate on those. For 
example:

find $DIR -type f -name '*.html' -exec sed -i 's///' {} \;

Flesh out the sed command as appropriate; i didn't copy the s/// 
arguments so that they wouldn't clutter it up. You might need to add a
-i switch to sed to make it edit the files in-place (i've added it 
above).

__
Daniel A. Ramaley
Network Engineer 2

Dial Center 118, Drake University
2407 Carpenter Ave / Des Moines IA 50311 USA
Tel: +1 515 271-4540
Fax: +1 515 271-1938
E-mail: daniel.ramaley@example.com


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links