You can 'grep "^line$" "filename"' and check the variable "$?". If it
is 0, there is the line. If 1, there isn't. The script maybe like,
line1 = "any line"
line2 = "another line"
for i in *; do
grep "^$line1$" $i;
if [ x$? = x1 ]; then
echo $line1 >> $i;
grep "^$line2$" $i;
if [ x$? = x1]; then
echo $line2 >> $i;
fi
fi
done
On Dec 7, 2007 3:42 PM, Chen <[EMAIL PROTECTED]> wrote:
> On Dec 7, 2007 3:04 PM, J. Lo <[EMAIL PROTECTED]> wrote:
>
> > Guys,
> >
> > Need your help here on the task automation. Basically here is what I want to
> > do.
> >
> > 1. I have around 1000 folders that the name of the folders is tied to the
> > username, eg. folder gilbert belong to user gilbert, etc.
> > 2. Inside these 1000 folders, there is a sub folder and a file called
> > win.ini that contained a lot of parameters. All users have the same file and
> > maybe same contents.
> > 3. I want to do a backup copy of win.ini to eg. win_backup.ini.
> > 3. After backup, I need to change certain parameters inside win.ini for
> > every folders, eg. homes=p:\windows\testing to homes=c:\windows\testing.
> > 4. In addition to that I need to append 2 new lines at the end of the file
> > and pre checking must be done, if the 2 lines are there then don't need to
> > append.
> > 5. Lastly, I want to change all the 1000 folders, including sub-folders
> > ownership to the owner's name, eg. change ownership of folder gilbert\* to
> > gilbert.
> >
> > Can the above task be automated using shell script or advanced programming
> > language, eg. Java is needed?
> >
> > Please help. Thanks.
> >
> > Cheers,
> > J.Lo
> > _______________________________________________
> > Slugnet mailing list
> > [email protected]
> > http://www.lugs.org.sg/mailman/listinfo/slugnet
> >
> >
>
> Hi, these operations can be done in shell scripts. And it maybe better
> to write several short scripts and do these things one by one, unless
> you need to conduct these operations often.
>
> A quick think gives these scripts, but they need some
> "trial-and-error". Copy the whole directory to another place and try
> on the copy.
>
> 3. for i in *; do cp $i/win.ini $i/win_backup.ini; done
>
> 3. for i in *; do cat $i/win.ini | sed -e
> 's/p:\\windows\\testing/c:\windows\testing/g' > $i/win.new && mv
> $i/win.new $i/win.ini; done
>
> The "pre-checking" in the 4th step is a little more tricky, esp. if
> the two lines is possiblly not at the end of the files...
>
> 5. for i in *; do chown -R $i $i; done
>
> Cheers,
>
> PQ
> --
> Best Regards,
> Puqing Chen
> [EMAIL PROTECTED]
>
--
Best Regards,
Puqing Chen
[EMAIL PROTECTED]
_______________________________________________
Slugnet mailing list
[email protected]
http://www.lugs.org.sg/mailman/listinfo/slugnet