LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-14-2015, 03:57 AM   #1
preetham.66666
Member
 
Registered: Jan 2015
Posts: 33

Rep: Reputation: Disabled
redirect output to another file


Hi,

I want to append output to another file exactly at scecond line

I know below command will work
sed '2 i whatever_line_of_text_you_wanted_to_INSERT' filename.txt

But i want to append output of echo command to second line of my file

Below command is not working
echo "11" | sed '2 i whatever_line_of_text_you_wanted_to_INSERT' filename.txt

Please help me.
 
Old 01-14-2015, 07:07 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
in bash the redirect operator is >, if you want to append you will need to use >> .
so:
Code:
first command > file
second command >> file
is the way
http://wiki.bash-hackers.org/howto/redirection_tutorial
 
Old 01-14-2015, 07:33 AM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Code:
head -n 1 inp_file > out_file;

lines=`cat inp_file | wc -l`;

lines=$((lines-1));

tail -n $lines inp_file > tmp_file;

echo "11" >> out_file;

cat tmp_file >> out_file;

rm tmp_file

Last edited by veerain; 01-14-2015 at 07:35 AM.
 
  


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
how to redirect input and output to one file dspjm Linux - Software 1 12-08-2012 09:16 PM
[SOLVED] cannot redirect output to file please help figure20012 Linux - Newbie 9 07-22-2012 07:09 PM
output redirect back to file mathfeel Linux - Software 1 03-21-2007 12:28 PM
How to redirect output to a file? mus1402 Linux - Newbie 2 02-05-2006 09:42 AM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 06:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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