Re: automated editing of text files
On Fri, Sep 16, 2011 at 5:14 PM, Bonno Bloksma <email@example.com> wrote:
>>> linbobo:~/sedtest# sed 's_\n<pre>\n_\n<pre>\n\n_' <original.txt
>>> >new.txt linbobo:~/sedtest# less new.txt
>> You want to change the regexp here. In regular expressions '^' matches
> start of line and '$' matches end of line.
>> Your sed instruction above should be something like 's/^<pre>$/<pre>\n/',
> or more generally 's/^\(<pre>\)$/\1\n/'.
> Ok, I've got most of it. The last part is more of a bash problem I think as
> most of the files have spaces in them. Not my idea, it's how the files were
> delivered to me. :-(
> So the command line:
> for i in `ls *.txt` ; do ./add-pre-nl.sh $i; done
> does not cut it as it chops the filesnames up and issues each part to the
> add-pre-nl script. :-(
> If I just use
> ./add-pre-nl.sh file\ name\ with\ spaces.txt
> it will produce the result I want.
Use "$i" for the filenames with spaces to remain whole.