Re: Add to text file from command line via echo... possible to add to a particular line?[Scanned]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris Bradford wrote:
> Hi guys,
> 
> I'm making a setup script for my Linux boxes that re-install Openldap
> and some other bits and bobs. I need to add some text to /etc/pam.d/gdm
> for example, and it needs to be on a particular line in this file, not
> at the bottom.
> 
> For example using the command:
> 
> echo 'session   required   pam_mkhomedir.so skel=/etc/skel umask=0077'
>>> /etc/pam.d/gdm
> 
> Will only add this to the bottom of the file, can I get around this, it
> needs to be on the same position on all machines, ie line 8.
> 
> Cheers,
> 
> -Chris
> 
You might be better off using something like sed to find the
specific line you want to insert the new line after. That way, the
specific line number is not critical. For removal, you can search
for your specific line and delete it. Something like:

sed -i -e "/some line format/anew line" <file name>

The -i option means edit the existing file. (You can use i.bak to
create a backup file called <file name.>.bak.)

The /some line format/ searches for a line with "some line format"
in it. You can also use /^some line format$/ to require an exact match.

If you are sure you want to insert at a specific line, try something
like:

sed -i -e "8iNew Line" /etc/pam.d/gdm

This will insert "New Line" at line 8 of the file. You may find it
easier to put your sed commands in another file. This is especially
handy if you want to do more then one command. To do that, replace
-e "command string" with -f <sed script>.

Mikkel
-- 

  Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux