little shell/script question

little shell/script question

Post by Mike » Wed, 18 Apr 2001 03:40:42



Greetings,

i like to format a lot of text files with one call of my script (lets assume
cat is my script). I've done the following:

find * -type f | grep txt$ | xargs cat > ahugefile

The above command writes the contents of all files that end with txt into
one file called 'ahugefile'.
The problem is that i like to create a new file for each sourcefile.
How do i have to modify the above command, that each sorcefile will be piped
into a file with a different name than the
sourcefile?

I hope someone knows...
Thanks in advance for any help,
Mike.

 
 
 

little shell/script question

Post by Michael Heimin » Wed, 18 Apr 2001 04:05:09



> Greetings,

> i like to format a lot of text files with one call of my script (lets assume
> cat is my script). I've done the following:

> find * -type f | grep txt$ | xargs cat > ahugefile

> The above command writes the contents of all files that end with txt into
> one file called 'ahugefile'.
> The problem is that i like to create a new file for each sourcefile.
> How do i have to modify the above command, that each sorcefile will be piped
> into a file with a different name than the
> sourcefile?

for i in `find . * -type f | grep t`; do echo "cat" $i "> "
$i".dat";done

You need to use a loop like the one above which works with bash.
You may need to remove the "echo" and a some """, just try it out.

Hope this helps, as I'm not really sure if I understood what you mean?

Michael Heiming

 
 
 

little shell/script question

Post by Bill Marcu » Wed, 18 Apr 2001 09:02:22



>Greetings,

>i like to format a lot of text files with one call of my script (lets
assume
>cat is my script). I've done the following:

>find * -type f | grep txt$ | xargs cat > ahugefile

>The above command writes the contents of all files that end with txt into
>one file called 'ahugefile'.
>The problem is that i like to create a new file for each sourcefile.
>How do i have to modify the above command, that each sorcefile will be
piped
>into a file with a different name than the
>sourcefile?

find . -type f -name '*txt' | while read x; do cp "$x" "$x.new"; done
 
 
 

little shell/script question

Post by Nathan Dietsc » Fri, 20 Apr 2001 17:56:18


Mike,

If I see this correctly you are trying to write all file which start with
txt into one big file. correct ?

Quote:> The problem is that i like to create a new file for each sourcefile.
> How do i have to modify the above command, that each sorcefile will be
piped
> into a file with a different name than the
> sourcefile?

OK to integrate both creating the large file and copying the source.

first null the file

cat /dev/null > ahugefile

for file in `find * -type f -name 'txt*'`
do
    cat $file >> ahugefile
    cp $file $file.new
done

There are more efficient ways of doing this but I find this to be the
cleanest.

Regards,

Nathan

 
 
 

1. little shell/script question

Greetings,

i like to format a lot of text files with one call of my script (lets assume
cat is my script). I've done the following:

find * -type f | grep txt$ | xargs cat > ahugefile

The above command writes the contents of all files that end with txt into
one file called 'ahugefile'.
The problem is that i like to create a new file for each sourcefile.
How do i have to modify the above command, that each sorcefile will be piped
into a file with a different name than the
sourcefile?

I hope someone knows...
Thanks in advance for any help,
Mike.

2. Printers?

3. shell script within shell script (general question)

4. Help Please!

5. Unix Shell Script to convert between Big and Little Endian

6. SPARC without keyboard

7. Simple Shell Script with Little Problem

8. SBPC driver loads slowly in kernels?

9. little help shell scripting

10. Newbie needs a little help on shell scripts (ksh)

11. A little Shell script

12. little shell script problem

13. nifty little shell/perl scripts