Solved

how to insert a string at a particular line in linux

Posted on 2014-03-06
4
447 Views
Last Modified: 2014-03-07
how to insert a string at a particular line in linux
i want to insert mystring at line after teh line number 134
0
Comment
Question by:pvinodp
  • 2
4 Comments
 
LVL 6

Assisted Solution

by:Vijay Pratap Singh
Vijay Pratap Singh earned 200 total points
ID: 39911960
Hi with the help of sed command you can insert string at particular line number for more info refer:

http://www.garron.me/en/linux/add-line-to-specific-position-in-file-linux.html
0
 
LVL 12

Accepted Solution

by:
tel2 earned 300 total points
ID: 39911967
sed -i '134 a\
mystring' filename
0
 

Author Closing Comment

by:pvinodp
ID: 39912066
.*
0
 
LVL 12

Expert Comment

by:tel2
ID: 39913921
Hi pvinodp,
Thanks for the points.

Personally, I preferred the coding style of rickyzen's solution, since it could be done on 1 line.  It could be easily modified to update the original file, like this:
    sed -i '134imystring' filename

However, I notice that you gave our answers a 'B' grade.
I see in the "Grading Tips" which show to the right of the 'A', 'B', 'C' grade selector, when awarding points, that a 'B' grade is appropriate when:
    "The Expert(s) provided an acceptable solution, or a link to an acceptable solution. May assign if you needed a bit more information to complete the task."
What was lacking in our solutions?  What more information did you require?  I notice you didn't ask for any more information, which meant we didn't have any opportunity to provide it.  I know our answers were brief, but I thought they were all that was required to give you what you asked for, and I've seen nothing to the contrary since, apart from a 'B' grade.

Looking forward to hearing your point of view.

Thanks.
tel2
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Changing passwords in Linux Systems 3 41
AD LDAP LDS 3 48
Reset Root Password on CentOS 6 4 44
Error Message during CentOS 7 Minimal Install 3 34
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now