Then what is the syntax to have the replace take the letter it finds and strip out the HTML around it?

I know about Sigil, and Calibre for that matter. It is conversion from a PDF to e-Pub using Calibre that created less than perfect results I am trying to clean up using Sigil and regular expressions.

So, my question is still relevant for this forum! At the heart of it I am trying to clean up HTML syntax using regular expressions.

What is the syntax to have the replace take the letter it finds and strip out the HTML around it?

You're over-complicating it. I am not talking a Regex in association with PHP or putting it in a database.

Is it possible in a good text editor that supports regular expressions to perform the replace substituting what is found (using the criteria in my original post) with a space and whatever letter is found?

</p>\n\n <p class="calibre2">[a-z] 

Regular expression search finds

</p>\n\n <p class="calibre2">e

I want to replace automatically with

 e (think of a space in front of the e-does not show up with code syntax)

Can this be done in the editor?

Is the code </p>\n\n <p class="calibre2"> not HTML? Last time I looked it is. I think it is relevant for others might want to learn about code clean-up using regular expressions.

As for language, editing e-pubs is a form of HTML and CSS in a very structured container file. So, I think this post is entirely relevant fot this area of the site.

Would you care to contribute how to answer my question?

I am cleaning up the code in an e-pub file. It was converted from a PDF and a number line break occur where not desired. I am using the following syntax to find the errand breaks </p>\n\n <p class="calibre2">[a-z]

For replace I wish to insert a space and whatever the character is found by the [a-z].

Is this feasible with only a regular expression replace, no script?

Are you using any CSS3 code?

No, I am not.

I followed the advice above of LastMitch. I am still having the same issue as depicted in the first screen shot shared above. However, only in Firefox (Kubuntu & Windows). Google Chrome (Kubuntu & Windows), Opera (Kubuntu & Windows), MSIE 8 (Windows) and Safari (Windows) all display the page as it should.

An inspection of the page in Firebug yields the following for all CSS declarations in use. It is identical to those listed in Opera or Chrome:

#navigace li a:hover {
  background-color: #581B08;
  color: #F5F5DC;

#navigace li a {
  display: inline-block;
  font-size: 11px;
  font-weight: bold;
  line-height: 37px;
  padding: 0 20px;
  text-transform: uppercase;

#navigace li a:hover, #navigace li:hover a, #navigace li.sfHover a {
  text-decoration: none;

html, body, div, span, applet, object, iframe, 
h1, h2, h3, h4, h5, h6, blockquote, pre, a, abbr, 
acronym, address, big, cite, code, del, dfn, font, 
img, ins, kbd, q, s, samp, small, strike, sub, sup, 
tt, var, center, dl, dt, dd, ul, li, fieldset, form, 
label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
  border: 0 none;
  font-family: inherit;
  font-style: inherit;
  margin: 0;
  outline: 0 none;

#navigace li {
  list-style: none outside none;

I have tried toggling off font-size and line-height found in #navigace li a but to no avail. Even looking at the Box-Model under Computed in Firebug and padding-bottom does not change in regular or hover.

I am having a challenge with a hover state and css. In this pic of hovering over menu item Gallery the background bleeds down. This is the code for regular state:

#navigace li a {
    padding:0 20px;

To get rid of the bleed state, all I could find that would work was

#navigace li a:hover {

However, if the user hovers over the active menu item - as in this pic of hovering over menu item Store the background effect changes to only encompass a smaller area of the anchor, not the whole menu item.

Input for how to rectify this so the hovered on menu item does not bleed down would be most appreciated.

Thanks for the input. Your advice helped and pointed out a flaw in the how-to I used to set-up all of the server aliases on my previous install of Ubuntu. Not one of those had a ServerName directive and they worked.

I am trying to set-up some virtual hosts on a fresh install of Ubuntu 12.04 and not getting expected results. I am using this tutorial which I have used before without fail.

The challenge seems to come with restarting apache.

$> sudo service apache2 restart 
  * Restarting web server apache2   apache2: Could not reliably determine the server's fully qualified
  domain name, using for ServerName
  .. waiting apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName

If I go through all of the steps, the alias I am trying to establish renders the root of localhost in my browser not the path set in sites available file.

Attempting to troubleshoot this, I removed the site with a2dissite and removed the site in /etc/hosts. Restarting apache as above, I receive the same error result. So it would appear something is not working properly in the first place, never mind attempting to add more hosts.

/etc/hosts content without additional hosts, rendering error messages found above:   localhost   daniel-dell-ubuntu

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Excerpt for the sites-available directory for lh-test_site

    DocumentRoot /var/www/test_site
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    <Directory /var/www/test_site/ >
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all

Working on some CSS for a WordPress site, I came across this:

img[class*="attachment-"] {
    height: auto; /* Make sure images with WordPress-added height and width attributes are scaled correctly */

Are thes wild cards that will work for any instance of, for instance, class="wp-image-a", class="wp-image-b", class="attachment-vacation"?

By and large, I don't want replacements. I merely wish to remove the selectors prefaced with UNUSED and for the declarations that are singular, strip the entire declaration and rule from the CSS.

So, based on the code examples provided, I need search paramets that will go something like ", UNUSED [everything to next]," "UNUSED [everything to next]," "UNUSED [everything to space {] but leave the space {" "UNUSED [everything to ]}\n"
I know those are not appropriate syntax. Just My pseudo-code.

I want to use regular expression to clean-up some CSS files.

I used a Friebug add-on, CSS Usage, to analyse some CSS from a jquery demo. Exporting the files, this add-on places 'UNUSED' at the front of a declaration and rule. Below is a sample of the output.

html #demo-config-menu li a:link,
UNUSED* html #demo-config-menu li a:visited {
 padding:1px 8px 2px;

UNUSED#demo-config-menu li a:active,
#demo-config-menu li a:hover {

UNUSED#demo-config-menu h4 {
 font-size:13px; color:#666; font-weight:normal; border:0; padding-left:18px;

New to regular expressions, I have tried in vain to come up with search parameters for what I want.

  1. a way to search compound selectors for instances of UNUSED and the selector that follows, be it the first or second selector within a CSS rule (as in first two code samples);
  2. search for a complete declaration and rule as in the last code example

I have looked at tutorial on youtube and other sources. I can have success with anything up to and before ' {' but can not the search parameters to work beyond that.

Anyone have suggestions?

I am wondering if I am trying to do too much or if there is a better way for a client-side form I wish to create.

A limited working prototype for what I have so far appears here:

I am using a table as the frame for the form so that rows can be dynamically added or deleted (after clicking a checkbox at the left of a row's beinning)

I am looking for a method/plug-in that will allow me to sort the form by the Order column. As users enter data, they might forget to add something in sequence. I want the user to be able to append at the end and edit the sort order, click on a link to sort the rows by order before sending the form to be processed by php.

Can this be done? If a solution can satisfy all these needs and not use a table, I am open to that also.

Googling for a solution, I found many javascripts for sorting tables, but not tables serving as a structure for form input elements.

Assistance would be greatly appreciated.

I am looking for a method with one or more php functions for manipulating form textarea data. I want to clean it up by indenting it and wrapping it after a certain length with EOL but not necessarily html <br> or <br /> before it is inserted in My database.

Or alternatively, I want to take a large block of text from the database and clean it up before populating it in a form textarea.

Can anyone offer which series of functions might satisfy these needs?

Thank you all for the constructive ideas to solve this. I have tried include, include_once, require, require_once.

Using any of the above variations did not trigger an error in the apache error log.

I know for certain it is not a challenge with spelling or some similar syntax error for if I give an absolute path to the include syntax, the include will work.

I've gone over things with a fine tooth comb. There are no typos. It seems this is an issue with PHP 5.

Good day,

I am working on atomizing a template creating includes in a sub-directory called includes and calling them like this

<?php include 'includes/head.php'; ?>

I have also tried

 <?php include('includes/head.php'); ?>

My page won't load. All I get is a blank browser window. I tried tailing the error.log and nothing is appearing there.

Googling the issue, I have come across this challenge some had on network servers after upgrading from PHP 4 to 5 and Zend optimizer. My server isn't complex as it is only a development environment.

Has anyone else had a similar issue and can offer a solution?

There was something, I don't know what, in the code. Something I couldn't figure out. Rewrote the file from scratch and now it works fine.

Yes, that syntax is included. I merely did not present it here for the sake of brevity.

I'm baffled by something in a small script I wrote. The purpose of the script is to compare 2 files on a system. Somehow a tree structure was copied and am fairly certain that the files are identical

The command line is as follows:

/ /home/daniel/Documents/workspace/www/

This is the script:

find $1 -name "*.*" | while read file
    if diff $file $file2 >/dev/null ; then
      rm $file
      echo Different 

The variable file2 is defined by stripping out the path defined in $1 and adding '/var' to the front of it. The path would become /var/www/ and the same filename.
If I run the file with bash -x to echo the steps for debugging, it works fine. If I don't debug, then I receive an error of Bad Substition at line 10 (the last line of the script).

Thanks all. These solutions work

A script I am writing on works on the DVD present in the drive at time of script execution. I want to extract merely the label of whatever appears after '/media/';

./ /media/DVDRW-43/

An obvious solution would be to get the substring by

path='echo ${file:7:9}' #renders DVDRW-43

but I would rather a substring extraction based on capturing from the second occurence of '/' to third occurence of '/'. I can't get my head around regex or the substring commands to do this.

I am trying to write a script that will facilitate cataloguing various files on a backup medium. Looking at what's available, only stat seems suitable but it outputs the data with a lot of formatting I don't require and would take a lot of scripting to massage into what I want. ls -l at the CLI would result in a lot of scripting as well.

There are four pieces of information I need and would like them somehow delimited for easy import to a spreadsheet. In order they are:

File creation date and time to the minute
File size
File name
Label of the medium (DVD name)

I had developed a way to do this in Windows using JPSoft and found it a lot simpler than what it will take in bash.

Is there something other than stat and ls?

New to bash, I am trying to change the names of dozens of files as I switch over to Linux. I need something that will work recursively from the root of a directory. In my research I found something like this that I have adapted:

find /media/D_Drive/Music/ -name '*&*.*' -exec sh -c 'mv "$0" "${0%//\&/and}"' {} \;

In the above example I am trying to replace all occurences of '&' with the word 'and'.

However, running that at the CLI I get a message that amounts to the source and new filename are the same.

Is there a way to log all activity in a CLI? For instance, all of the mv commands that would occur from the above? Bash history will only log that command, not all the iterations that command will generate.

Thanks for taking the time to read this and if you can offer assistance even better.

Thanks ravi89. It'll do the trick. :)

I am looking for syntax I saw somewhere but can not find now. Working with the results of a find delete the files found.

The syntax is something like this:

for i in "${find . -name '*.ini'}"; do rm $i; done

Am I dreaming or is this possible?


I did some more research and discovered the command bash -x which runs the script in a debug mode so one can monitor the activity of a script. I discovered that my file containing the sub-directories was terminating in \r. \n was being removed with incorporating your suggestion of

   line2=echo -n $line  

it was just a matter of changing the encoding to UTF-8 and ending the lines in Unix instead of Windows format.

A good article for learning the debug features of bash scripting can be found at

As for the path being relative or absolute, it does not make a difference if I am in the root of the sub-directories or not. The file which contains the list of sub-directories contains paths which are absolute to the root


All is working well now. Thanks for your input.

I am new to bash shell scripting. Converting over to Linux before support for Windows XP fades into the sunset, I am redesigning and rewriting many scripts that worked using enhanced scripting language Take Command.

I am trying to evaluate whether a directory exists based on a list of directories in a text file. If I enter the following at the command line:

if [ -d "/media/D_Drive/Music/Rolling_Stones/1995-Voodoo_Lounge/" ]; then echo "True"; else echo "False"; fi

True echos to cli.

If I try:

while read line; 
if [  -d "$line" ]; then
    echo "exists $line";
    echo "Does not Exist - $line";
done < /media/D_Drive/Music/Albums-linux.txt 

all the values of $line come back as not existing

What am I missing? I have tried [ -d "$line" ] with and without quotes. I know it does not have to do with possibility of whitespace in the sub-directory name for that triggers a too many arguments error.

Thanks for the help, Gromit. Your answer worked perfectly. I am wondering though, working at the command line, how would I form the syntax for combining the two actions on line in one pass?

I am new to bash scripting. Is it possible to get a value returned on a nested variable? At the command line, the following code will generate desired ouput:

while read line; do echo -e "${line:21}"; done < Albums-linux.txt 

It takes a list of directories for albums and returns a substring of GroupName/albumName. For the next step, I want the result to replace the '/' with '-' I think my syntax should be something like"

while read line; do echo -e  "${"${line:21}"///-}"; done < Albums-linux.txt 

so the output is GroupName-albumName. But I get a result: ${"${line:21}"///-}: bad substitution
I also tried escaping the '/' I wish to substitute by escaping it `${"${line:21}"/\//-}
but still had the same result.

Am I trying to do too much at the command line and I have to write this in a script?