Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to insert a string at a particular line in linux

Posted on 2014-03-06
4
Medium Priority
?
462 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 600 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 900 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

927 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