Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] grep, sed, and cat - oh my!
- Date: Thu, 16 Sep 2010 19:07:09 +0200
- From: Nicolas Limare <nicolas+tlug@example.com>
- Subject: Re: [tlug] grep, sed, and cat - oh my!
- References: <4C924ACE.9000707@example.com>
- User-agent: Mutt/1.5.20 (2009-06-14)
Dave, > 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 You can make better: find ./ -name "*.js" -> gives you all the *.js files in the current directory cat $( find ./ -name "*.js" ) > all.js -> concatenates all these files into all.js > 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' You obviously want to use this substitution command: "s/something/something else/g" But the '/' in your sunstritution strings are clashing with the '/' in the substitution command. But, in fact, you can use any character in a sed command, so let's use one not appearing in your substritution strings. '%' for example. This version may work: 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 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? no. sed works line by line > And in either case, can I tweak it to only act on files with a ".html" > extension? Only give sed html files to work on, like find ./ -name *.html | while read FILE; do sed -i 's%...%...%g' $FILE; done -- Nicolas LIMARE http://nicolas.limare.net/ pgp:0xFA423F4FAttachment: signature.asc
Description: Digital signature
- Follow-Ups:
- Re: [tlug] grep, sed, and cat - oh my!
- From: Mattia Dongili
- Re: [tlug] grep, sed, and cat - oh my!
- From: Stephen J. Turnbull
- References:
- [tlug] grep, sed, and cat - oh my!
- From: Dave M G
Home | Main Index | Thread Index
- Prev by Date: [tlug] grep, sed, and cat - oh my!
- Next by Date: Re: [tlug] grep, sed, and cat - oh my!
- Previous by thread: [tlug] grep, sed, and cat - oh my!
- Next by thread: Re: [tlug] grep, sed, and cat - oh my!
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links