LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-01-2009, 12:19 PM   #1
starmonche
Member
 
Registered: Jan 2007
Location: Overland Park
Distribution: Centos6
Posts: 60

Rep: Reputation: 15
How to concatenate output of two commands to a file


I have a file called "query.sql" that looks like this:

SELECT
field1,field2,field3
FROM
sometable
WHERE
oldcondition


And I have a script called "maxdate.php" that returns this:

newcondition

I'm looking to replace the last line of the file "query.sql" with the output from the command "maxdate.php".

This command drops the last line of the file:
$ sed -e '$d' query.sql

And this gives me what I want to put in its place:
$ ./maxdate.php

How in the world can I combine the output of both commands and dump it into "query.sql"?
 
Old 05-01-2009, 12:28 PM   #2
oddsocks
LQ Newbie
 
Registered: May 2009
Location: Perth, Australia
Distribution: RHEL, Fedora
Posts: 1

Rep: Reputation: 0
I might be misunderstanding what you're trying to do, or the reasons why but what about:

sed -i '$d' query.sql ; ./maxdate.php >> query.sql
 
Old 05-01-2009, 12:31 PM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
sed -e s/oldcondition/`maxdate.php`/ query.sql

Note the symbols around maxdate.php are back ticks not single quotes. They tell the command line to execute maxdate.php and use its result (newcondition).

The sed line says substitute that result (newcondition) for oldcondition. It will output to screen. You'll have to redirect into a new file then copy the new file back over the original. (Ideally you'll also save a copy of original before doing that so you can recover if you need to do so.)
 
Old 05-01-2009, 12:33 PM   #4
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
I think you really want
Code:
(sed -e '$d' query.sql;./maxdate.php) > query.sql
HTH

Forrest
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenate Problem - First & Last file are Overlaying donanap Linux - Newbie 5 03-04-2009 04:38 PM
varied output for linux df and du commands on same file system bzlaskar Linux - Newbie 1 12-11-2007 10:41 PM
using commands to output path, filename and info to a txt file bob_man_uk Linux - General 3 05-11-2006 03:31 PM
Concatenate binary file iftiuk Linux - General 6 05-16-2005 09:11 AM
Bash: How to concatenate the output of different commands? J_Szucs Programming 1 11-13-2003 08:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:18 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