Solved

how to insert a string at a particular line in linux

Posted on 2014-03-06
4
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

624 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