Solved

how to insert a string at a particular line in linux

Posted on 2014-03-06
4
454 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to monitor servers ? 4 64
simple bash script needed to unpack tar.gz 4 61
Logrotate Every Saturday 5 44
[bash] complex renaiming file 2 20
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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