LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-19-2011, 03:10 PM   #1
tech_jedi
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Rep: Reputation: 0
Adding a line to a queried list of files.


I am trying to add a line of text to hgrc files for Mercurial Repo's

The file is found normally in a hidden .hg directory under the repo.

Example
/hg/repo1/.hg/hgrc

There are 20 or so repo's using this pathing.

I need to add a "deny_read = username" to the end of each of these hgrc files.

Suggestions either in shell script format, or a single line?

May thanks.
Wes
 
Old 04-19-2011, 03:31 PM   #2
ShadowCat8
Member
 
Registered: Nov 2004
Location: Ontario, CA
Distribution: Gentoo, Arch, (RedHat4.x-9.x, FedoraCore 1.x-4.x, Debian Potato-Sarge, LFS 6.0, etc.)
Posts: 235

Rep: Reputation: 52
Well,

For the example you gave above, I can see something like:
Code:
 ~ # for i in `find /hg/ -name "hgrc" -print` ; do echo "deny_read = username" >> ${i} ; done
Now, I'm big on testing before making changes on files with no backups, so to make sure that everything you are expecting is what is going to happen, make a small change to the above line to see what *will* happen before it does:
Code:
 ~ # for i in `find /hg/ -name "hgrc" -print` ; do echo "Adding 'deny_read = username' to ${i}" ; done
HTH. Let us know.
 
Old 04-19-2011, 04:24 PM   #3
tech_jedi
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Worked like a champ!

Thanks so much.
 
Old 04-19-2011, 04:33 PM   #4
tech_jedi
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Ok, so how do we change it to a bash script called "add_deny" that would accept the usernames as its arguments.

#!/bin/bash -x

for i in `find /hg/ -name "hgrc" -print` ; do
echo "deny_read = username" >> ${i}

done


I understand that $0 is the first argument, $1 would be the first thing after the script.

Oh and of course if this was run again it would need to actually add argments to the existing line.

Thanks again though at least this one time add is already done. Now I just need to figure out how to automate this for the future.
 
Old 04-19-2011, 06:50 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
If I understand you
Code:
./myscript.sh user

#!/bin/bash -x

user=$1
for i in `find /hg/ -name "hgrc" -print` ; do
echo "deny_read = $user" >> ${i}
done
That adds (appends) a new line to each file.
If you want to 'edit' the line automatically, you'll probably use sed http://www.grymoire.com/Unix/Sed.html#uh-0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
'E:Malformed line 54 in source list /etc/apt/sources.list (dist parse), E:The list of vsssuccess@gmail.com Linux - Desktop 1 11-17-2010 08:17 AM
Adding a line to multiple files using Sed Tuxqi Linux - General 9 11-27-2009 03:23 PM
LXer: fdupes - Command line tool to find and list/delete duplicate files LXer Syndicated Linux News 0 10-28-2008 03:40 PM
Command Line Help: Remove a List of Files lukasbradley Linux - Newbie 2 08-17-2005 04:21 AM
adding files through command line browser Linux - General 6 05-21-2005 06:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration