BashScripts.org
http://bashscripts.org/forum/

echo-ing to multiple files at once
http://bashscripts.org/forum/viewtopic.php?f=8&t=1369
Page 1 of 1

Author:  kifno [ Tue May 03, 2011 6:02 pm ]
Post subject:  echo-ing to multiple files at once

okay so say you're in directory /a/b/c/

and folder c has folders 1, 2, 3, 4, 5, 6, and....

and there is a file called "file" in folders (1-6)

but now that we know that file is in all 6 of those folders lets say that in folders 1,4, and 5 the value of the file "file" was 100 and in all the other folders the value for that file is 0.

if i only want to change the value of the files that have their default value as 100 to lets say.....200

but i want to do it all at once besides just running:

echo 200 > /a/b/c/1/file
echo 200 > /a/b/c/4/file
echo 200 > /a/b/c/5/file

and letting the others stay 0.


...any help is appreciated thanks a lot

Author:  Watael [ Tue May 03, 2011 7:09 pm ]
Post subject:  Re: echo-ing to multiple files at once

Hi,


do you have the gift of ubiquity?
bash either.

Author:  choroba [ Wed May 04, 2011 9:30 am ]
Post subject:  Re: echo-ing to multiple files at once

Something like this?
Code:
sed -i~ 's/^100$/200/' /a/b/c/[123456]/file

Author:  kifno [ Wed May 04, 2011 7:49 pm ]
Post subject:  Re: echo-ing to multiple files at once

choroba wrote:
Something like this?
Code:
sed -i~ 's/^100$/200/' /a/b/c/[123456]/file

could you explain exactly what that does? thank you

Author:  choroba [ Thu May 05, 2011 8:28 am ]
Post subject:  Re: echo-ing to multiple files at once

kifno wrote:
choroba wrote:
Something like this?
Code:
sed -i~ 's/^100$/200/' /a/b/c/[123456]/file

could you explain exactly what that does? thank you

It changes "100" standing solely on a line to "200" in all the "file"s in the given directories. Did I get your specification right?

Author:  kifno [ Thu May 05, 2011 9:58 am ]
Post subject:  Re: echo-ing to multiple files at once

choroba wrote:
kifno wrote:
choroba wrote:
Something like this?
Code:
sed -i~ 's/^100$/200/' /a/b/c/[123456]/file

could you explain exactly what that does? thank you

It changes "100" standing solely on a line to "200" in all the "file"s in the given directories. Did I get your specification right?

say if you don't know all the folders inside the directory /a/b/c/

would it be
Code:
sed -i~ 's/^100$/200/' /a/b/c/[ls -d]/file
?

Author:  choroba [ Thu May 05, 2011 3:14 pm ]
Post subject:  Re: echo-ing to multiple files at once

kifno wrote:
say if you don't know all the folders inside the directory /a/b/c/

would it be
Code:
sed -i~ 's/^100$/200/' /a/b/c/[ls -d]/file
?

If you want everything, use *.

Author:  kifno [ Fri May 06, 2011 5:32 am ]
Post subject:  Re: echo-ing to multiple files at once

choroba wrote:
kifno wrote:
say if you don't know all the folders inside the directory /a/b/c/

would it be
Code:
sed -i~ 's/^100$/200/' /a/b/c/[ls -d]/file
?

If you want everything, use *.


thanks i'll see if that works for my purpose :D

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com