bad: Want to insert a line into a text file using "sed" command
Hi all,
I've been reading tutorials of Linux sed command, but haven't got anything yet. the problem is : I want to insert a line into my DNS database file which has a pattern like below: <Domain name> 3tabs here <IN> <A> <ip address> the question is : how to add a line into a file like this using linux sed command? I have problem inserting tabs and the spaces! could you please help me with the answer? |
Code:
ruby -i.bak -ne 'print "#{$_}insert line\n" if $_=~/Domain name/ or print' file |
Quote:
it would be great if you could help me with SED command. |
Code:
$ sed -i '$ a linuxquestions.org\t\t\t<IN> <A> <ip address>' input_file |
Please be a bit more specific about what you want to do. What do you mean by "insert" exactly? Do you need the line to go in a specific place? And if so, how can you specify that location? And what kind of text does the file contain, exactly? In other words, what should the before and after files look like?
In particular, sed has two commands, i and a, for insert and append. These are used with address spaces for adding text before or after a line containing a targeted pattern. Code:
sed '/sometext/i insert this line before sometext' file Three pages with useful info on sed: http://www.grymoire.com/Unix/Sed.html http://sed.sourceforge.net/sed1line.txt http://sed.sourceforge.net/sedfaq.html |
thanks quanta,
what if the 'linuxquestion.org' and 'ip address' are the arguments which were asked from the user by a script? |
Code:
quanta@gentoo ~ $ cat input |
Quote:
|
All times are GMT -5. The time now is 04:52 AM. |