- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh? inserting line into files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2005 02:26 PM
тАО02-02-2005 02:26 PM
I know this is an easy one, and will just say that I caught a flu which makes my head ache a bit too much.
I need to insert a css reference into a LOT of html files.
so far I've thought about
mv foo.html foo.html.bak
while read line < foo.html.bak
do
echo $line >> foo.html
if [ echo $line | grep '' 2>dev/null 1>/dev/null ]
then
echo "$CSS_THINGY" >>foo.html
fi
done
but somehow I get the feeling that this might
blow up or just be a very strange way of doing it.
I'd love some recommendations!
Solved! Go to Solution.
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2005 02:47 PM
тАО02-02-2005 02:47 PM
Re: ksh? inserting line into files
cp foo.html foo.html.bak
> foo.html
while read line < foo.html.bak
do
echo $line >> foo.html
if [ echo $line | grep '' 2>dev/null 1>/dev/null ]
then
echo "$CSS_THINGY" >>foo.html
fi
done
-denver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2005 02:56 PM
тАО02-02-2005 02:56 PM
Re: ksh? inserting line into files
I chose mv because it's not updating the original file at all, but forgot about the new file.
then a
cp -p foo.html.bak foo.html and a
> foo.html
would be needed to keep everything in sync.
also, I noticed the if clause must read
if [` echo $line | grep '' 2>dev/null 1>/dev/null `]
I'll try it later, right now I'm just to dizzy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2005 02:59 PM
тАО02-02-2005 02:59 PM
Re: ksh? inserting line into files
I'm sure one of the perl gurus will wake up and solve this one w/ a few lines of perl script for you.
-denver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2005 02:59 PM
тАО02-02-2005 02:59 PM
Re: ksh? inserting line into files
-su[4]: dev/null: cannot create [No such file or directory]
-su[4]: []: not found [No such file or directory]
-su[4]: dev/null: cannot create [No such file or directory]
-su[4]: []: not found [No such file or directory]
-su[4]: dev/null: cannot create [No such file or directory]
-su[4]: []: not found [No such file or directory]
-su[4]: dev/null: cannot create [No such file or directory]
-su[4]: []: not found [No such file or directory]
-su[4]: dev/null: cannot create [No such file or directory]
(see You in 12 hrs :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2005 03:21 PM
тАО02-02-2005 03:21 PM
Re: ksh? inserting line into files
--------
if [ echo $line | grep '' 2>dev/null 1>/dev/null ]
then
....
-----------
with :
-------------
echo $line | grep -q ''
if [ $? -eq 0 ]
then
......
-----------
BTW, the error messages printed by your script was
bacause of typo ('dev/null' instead of '/dev/null')
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2005 04:58 PM
тАО02-02-2005 04:58 PM
Solutionrequired perl alternative:
perl -i -ne 'print; print "css\n" if (/<\/title/)' x.html
If you'd need a line before a marker it reduces to:
perl -i -pe 'print "css\n" if (/<\/title/)' x.html
The "-i" creates a temp file. The alternative is the old
perl -ne 'print; print "css\n" if (/<\/title/)' < x.bak > x.html
you can pull in an shell symbol through $ENV{name}
perl -i -ne 'print; print "$ENV{\"XX\"}\n" if (/<\/title/)' x.tmp
and one of many awk solutions:
awk 'BEGIN {css=ENVIRON["CSS_THINGY"]}{print}/<\/title>/{print css}' x.tmp
CHeers,
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2005 12:20 AM
тАО02-03-2005 12:20 AM
Re: ksh? inserting line into files
2>dev/null 1>/dev/null
There is a / missing hence the errors.
Secondly, if you run a faulty script twice, you loose your original.
what about
awk '/<\/title>/ {print $0;print "CSS_THINGY";next;}{print $0}' foo.html
greetings,
Michael
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2005 09:19 AM
тАО02-03-2005 09:19 AM
Re: ksh? inserting line into files
And Hein - thank You for trying to build something more reasonable than that 'late night dilemma' I made - I chose Your awk solution, it takes well below a second for 100 files, which is very acceptable!
Michael - You've been right about the fact that I'd lose the originals by every second run. It was no issue because the files will be regenerated quite often but it's well worth noting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2005 09:21 AM
тАО02-03-2005 09:21 AM