LinuxQuestions.org
Review your favorite Linux distribution.
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 08-24-2009, 05:37 AM   #1
mrq
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
Question [Bash] - sed - read commands from file


Hi, it's my first post in this forum.I just started bash programming to automate some things on my server. I've done about half of the job but I'm stuck with two issues because i'm not experienced.

1. I want to use sed to read a file and run the commands in that file.Basically I want to compile php but because configure param take multiple lines i put them in a separate file. Now from a script, lest's call it web.sh i want to read all param of php, from php_conf.txt, and run it. How do i do that ?

2. I want to read all lines from a separate file and append to an existing file, at the end, and then save it. For example I have the file bash_conf.txt and want all the lines from it to be appended, at the end, to file bash.txt and then save the file. How do i do that ?

Thank you
 
Old 08-24-2009, 05:51 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
1)
check the -f option for sed

2)
check cat and >> (redirection)
 
Old 08-24-2009, 05:51 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
<<EDit: Wim is faster than I am-----and also much more succinct!>>


Is this homework?

Quote:
I want to use sed to read a file and run the commands in that file
SED can run it's own syntax from a file---is that what you mean? (See this for the -f option to SED: http://www.grymoire.com/Unix/Sed.html#uh-16 More generally, that site is the best SED tutorial)

Quote:
Basically I want to compile php but because configure param take multiple lines i put them in a separate file. Now from a script, lest's call it web.sh i want to read all param of php, from php_conf.txt, and run it. How do i do that ?
Is this related to the SED question? Regardless, you do not "compile PHP". PHP is a server-side scripting language.

Quote:
I want to read all lines from a separate file and append to an existing file, at the end, and then save it.
Take a look at the "cat" command and also at the redirection operators ">" and ">>".

If you don't have it already, go to http://tldp.org and get the Bash Guide for Beginners.

Good luck and Welcome to LQ!!

Last edited by pixellany; 08-24-2009 at 05:54 AM.
 
Old 08-24-2009, 06:27 AM   #4
mrq
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pixellany View Post
<<EDit: Wim is faster than I am-----and also much more succinct!>>


Is this homework?

SED can run it's own syntax from a file---is that what you mean? (See this for the -f option to SED: http://www.grymoire.com/Unix/Sed.html#uh-16 More generally, that site is the best SED tutorial)

Is this related to the SED question? Regardless, you do not "compile PHP". PHP is a server-side scripting language.

Take a look at the "cat" command and also at the redirection operators ">" and ">>".

If you don't have it already, go to http://tldp.org and get the Bash Guide for Beginners.

Good luck and Welcome to LQ!!
What ? What do you mean "you don't compile php" ? If i'm wrong here maybe php.net is wrong also and half of the internet. Perhaps "install php from sources" is more apropriate but "compile php from sources" is definately not wrong.
Even if is my first post here I'm not a noob and this is not my homework.I'm not very experienced with linux, I'm a noob in bash, but please don't treat me with superiority, trust me is not the case. No offense, maybe I misunderstood but I'm having the impression that you're ironic.


Sturkenboom thank you.
pixellany also thank you for the links
 
Old 08-24-2009, 06:43 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Nobody is "treating you with superiority".

I mis-read "compile PHP" to mean "compile PHP code"----Sorry. I don't know why you need to install PHP from source, but you obviously know more about PHP than I do.

Quote:
I'm having the impression that you're ironic.
What does this mean? "Ironic" is not normally used as an attribute for a person.
 
  


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
Bash script using sed - how to pick something out of a file? gankoji Slackware 4 08-07-2009 06:15 PM
Sed to read the file and replace and insert the pattern saurabhchokshi Programming 2 06-12-2009 01:15 PM
Problem with Adjusting ToolChain.... sed: can't read >: No such file or directory lfs_rocks Linux From Scratch 4 03-08-2009 10:30 AM
Sed doesn't update file in bash script chilebiker Programming 4 06-14-2007 08:25 AM
Bash script, how to send commands and read replies from a modem ealdaz Linux - General 1 01-25-2006 08:01 AM

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

All times are GMT -5. The time now is 02:52 AM.

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