LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-25-2017, 11:05 AM   #1
Linoob45
LQ Newbie
 
Registered: Feb 2017
Posts: 1

Rep: Reputation: Disabled
Linux bash script to add a line in a config file


I'm having trouble thinking of how to add a line to a config file and keep the same syntax. I know how to add a line to the bottom of a file using a script but not somewhere in the middle for example my config will look something like this:

"config:
2nd line
3rd line
4th line
5th line"

How would a command/script look like to be able to add another line between 3rd line and 4th line with same formation? Thank you all for your time and help.
 
Old 06-25-2017, 11:28 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
You can insert lines in the middle of a file with sed quite easily. See its i command.

What kind of config file are you dealing with and what have you tried with sed so far?
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to add new line to mp3 playlist bash script punkska1977 Linux - Newbie 2 02-14-2012 07:39 AM
[SOLVED] changing a line in a config file while installing the program using bash script Joe_Louis Programming 11 07-23-2011 05:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration