
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tlug] grep, sed, and cat - oh my!
- Date: Fri, 17 Sep 2010 01:50:22 +0900
- From: Dave M G <dave@example.com>
- Subject: [tlug] grep, sed, and cat - oh my!
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.12) Gecko/20100826 Thunderbird/3.0.7
TLUG,
Hoping for a little help with my bash shell-fu. Well, actually, I have
no bash shell-fu, but I'm trying.
I essentially have two commands, and they're not working.
First a little back story: My goal is to take a whole bunch of
Javascript files I have and combine them all into one big Javascript
file so as to cut down on the number of file requests when my web page
loads. This is something I need to do whenever I upload my files, so I'm
looking to create a script that will automate the task.
The script needs to:
1. Copy all the site files to a new location so that I don't
accidentally destroy the originals.
2. Use cat to combine all the files in a directory.
3. Use YUI Compressor to minify the files.
4. Go through all the HTML files to make sure they now point to the new
combined Javascript file.
5. FTP the new files to the server.
Steps 1, 3, and 5 I've got locked down.
Steps 2 and 4 are tripping me up.
For combining the Javascript files in step 2, they are in
subdirectories. Like so:
Javascript/fileA.js
Javascript/fileB.js
Javascript/subdir1/fileC.js
Javascript/subdir1/fileD.js
Javascript/subdir2/fileE.js
Javascript/subdir2/fileF.js
I came across a command which supposedly might do the trick:
ls -1R|grep :$|sed 's/:$//g'| awk '{print $1"/*"}'|xargs cat > all.js
However, when I tried running it, it just returned a whole bunch of
lines like:
cat: ./subdir/*: No such file or directory
Is there anything obviously wrong with the syntax?
Can I also make it so that it will only combine files with the extension
".js"? Just for extra safety?
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'
... but I got this error:
sed: -e 表現 #1, 文字数 69: 「s」へのオプションが未知です
... and I thought I would need to use "grep" so that my line-replacing
would happen on multiple files... but does "sed" already act on multiple
files?
And in either case, can I tweak it to only act on files with a ".html"
extension?
I hope my questions are clear.
Thank you for any advice.
--
Dave M G
Home |
Main Index |
Thread Index