Script question...

Andrew L. Gould algould at datawok.com
Mon Jan 12 15:28:26 PST 2004


On Monday 12 January 2004 05:04 pm, Xpression wrote:
> Hi list, I've making a script to write the content of three text files to
> one file, but I want to separate each files by a delimiter like the name of
> the file.
>
> This is the script:
>
> #! /bin/sh
> path=/some/dir
> if !([ -f $path/this.one ]); then
>     for file in $path/file1 $path/file2 $path/file3; do
>  cat $file >> $path/this.one
>     done
> fi
>
> exit 0
>
> By now the output is:
>
>  Contents of file1
>  Contents of file2
>  Contents of file3
>
> And I want to be like this:
> -----------------------------------------------------------------------
>   file1
> -----------------------------------------------------------------------
>  Contents of file1
> -----------------------------------------------------------------------
>  file2
> -----------------------------------------------------------------------
>  Contents of file2
> -----------------------------------------------------------------------
>   file3
> -----------------------------------------------------------------------
>  Contents of file3
>
> any suggestion ??? Thanks...

I haven't tested it; but would this work:

 #! /bin/sh
 path=/some/dir
 if !([ -f $path/this.one ]); then
     for file in $path/file1 $path/file2 $path/file3; do
  echo '---------' >> $path/this.one
  echo $file >> $path/this.one
  cat $file >> $path/this.one
     done
 fi
 exit 0


Andrew Gould




More information about the freebsd-questions mailing list