Solved

how to insert a string at a particular line in linux

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

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 11

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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 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…

747 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

10 Experts available now in Live!

Get 1:1 Help Now