How can I append text to a string in a file
I was wondering if there's a way I can add text to a specific string in a file without opening it. For example, if I wanted to add a group to geneanthony in /etc/group is there a way I can search the file for any string with geneanthony in it and then append to the end ,users? Is there a way to append on the next line after a string so I can keep a file organized? For example, I like to put certain text near other text is this possible?
|
If I understand your questions, sed should do what you want. Here's a quick primer http://tldp.org/LDP/abs/html/x19673.html
|
Reply
Thank you I'm looking it up now!
|
You can't do anything to a file without opening it!!
To search for a specific string and add to it: sed "s/string/stringplusnewstuff/g" <oldfile >newfile Here is a good tutorial on SED |
Code:
sed -i 's:geneanthony:&,users:g' /etc/group |
All times are GMT -5. The time now is 04:15 PM. |