Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Combine Two Commands Output

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-13-2007
33junaid 33junaid is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 1 June 2010, 9:29 AM EDT
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Combine Two Commands Output

How i can combine output of two commands in one file.......i tried this but it is not working although each command is working good seperately.....


head -1 filename | tail -1 filename


i think there is problem with command concatenator?
Sponsored Links
    #2  
Old Unix and Linux 08-13-2007
lorcan lorcan is offline
Registered User
 
Join Date: May 2007
Last Activity: 13 August 2012, 12:14 AM EDT
Posts: 224
Thanks: 0
Thanked 2 Times in 2 Posts

Code:
(head -1 filename; tail -1 filename )> newfilename

Hope you are trying to print the first and last line to a new file

Last edited by lorcan; 08-13-2007 at 06:11 AM..
Sponsored Links
    #3  
Old Unix and Linux 08-13-2007
33junaid 33junaid is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 1 June 2010, 9:29 AM EDT
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Yes that is done.Thanks....wat if I want to insert some word in between the 2 commands but on same line?

head -1 filename; "Some Text" ; tail -1 filename > newfilename

it is taking "Some text" as command instead of text.......how to combine text now?
    #4  
Old Unix and Linux 08-13-2007
lorcan lorcan is offline
Registered User
 
Join Date: May 2007
Last Activity: 13 August 2012, 12:14 AM EDT
Posts: 224
Thanks: 0
Thanked 2 Times in 2 Posts

Code:
(head -1 filename; echo "Some Text" ; tail -1 filename )> newfilename


Last edited by lorcan; 08-13-2007 at 06:12 AM..
Sponsored Links
    #5  
Old Unix and Linux 08-13-2007
33junaid 33junaid is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 1 June 2010, 9:29 AM EDT
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
the second command after the echo starts in new line not on the same line.........
Sponsored Links
    #6  
Old Unix and Linux 08-13-2007
lorcan lorcan is offline
Registered User
 
Join Date: May 2007
Last Activity: 13 August 2012, 12:14 AM EDT
Posts: 224
Thanks: 0
Thanked 2 Times in 2 Posts
Use the -n option in echo if you want to display it in a single line.
Sponsored Links
    #7  
Old Unix and Linux 08-13-2007
33junaid 33junaid is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 1 June 2010, 9:29 AM EDT
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
echo -n 'Header is: '; echo -n head -1 file1.txt ; echo -n ' Trailer is: '; echo -n tail -1 file1.txt > new_file


Now the problem is that it is displaing all correct on the screen but when I open new_file, it just shows me this result:

tail -1 file1.txt > new_file

I want it to redirect all output in one line which it is showing on screen to new file..........
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can I combine these two commands into one? boyboy1212 Shell Programming and Scripting 2 03-28-2011 06:01 AM
Combine two lists From Multiple Grep commands. Erulisseuiin Shell Programming and Scripting 4 03-13-2011 07:59 AM
nawk, combine commands numele Shell Programming and Scripting 2 03-17-2010 12:03 PM
Combine commands Spoiler UNIX for Dummies Questions & Answers 2 05-30-2009 04:56 PM
Combine output on same line theninja Shell Programming and Scripting 3 01-14-2008 03:21 AM



All times are GMT -4. The time now is 09:46 AM.