[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: automated editing of text files

Bonno Bloksma wrote:
> 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

Eww..  Don't say `ls *.txt` there but just say *.txt there.  No need
for ls to be there.  Just let the shell do it.

> does not cut it as it chops the filesnames up and issues each part to the
> add-pre-nl script. :-(

Add double quotes around the variable to preserve the whitespace.

  for i in *.txt ; do ./add-pre-nl.sh "$i"; done

If there are no *.txt files then the file glob won't be expanded,
nothing to expand it to, and then your shell script will get a literal
"*.txt" as an argument.  If that minor point is important to you then
check that the file exists and simply break or continue if it does not.

  for i in *.txt; do
    test -f "$i" || continue
    ./add-pre-nl.sh "$i"


Attachment: signature.asc
Description: Digital signature

Reply to: