Debian This forum is for the discussion of Debian Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-01-2007, 11:40 AM
|
#1
|
Member
Registered: Jan 2006
Location: Mexico, city
Distribution: DEBIAN, OpenSolaris
Posts: 32
Rep:
|
Add lines to a file
hi,
How can i add the output of a command, to some lines of a file?
what i mean is this:
i have this file:
hola adios tschus
bye good gut
and i want to add the output of a command for example 'md5sum' at the end of the first line. So the file will be something like this:
hola adios tschus 3df61431sdfg13opd31sd315 /etc/fstab
bye good gut
|
|
|
03-01-2007, 12:11 PM
|
#2
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep: 
|
This question is a bit puzzling. So you want to add a md5 sum and a file name (/etc/fstab in your example) to the end of the first line of a text file? That's it?
|
|
|
03-01-2007, 12:29 PM
|
#3
|
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307
Rep:
|
Yeah what's that /etc/fstab?
To add a md5 at line 1, one possibility:
Code:
awk -vval=$(md5sum /tmp/u | cut -f1 -d\ ) 'BEGIN{v2=val} { if (NR==1) {print $0" "v2} else print; }' myfile
|
|
|
03-01-2007, 12:52 PM
|
#4
|
Member
Registered: Jan 2006
Location: Mexico, city
Distribution: DEBIAN, OpenSolaris
Posts: 32
Original Poster
Rep:
|
No, in fact is just an example of what is my objective. I want to add at the end of line two or more extra lines in text file that content several lines.
|
|
|
03-05-2007, 06:20 AM
|
#5
|
LQ Newbie
Registered: Feb 2007
Location: Singapore
Distribution: Debian Sarge/Etch
Posts: 19
Rep:
|
Assuming that your original text is in "a.txt" and the lines that you want to add in "b.txt" you can use the following command:
cat b.txt >> a.txt
Hope that helps.
|
|
|
03-05-2007, 06:22 AM
|
#6
|
LQ Newbie
Registered: Feb 2007
Location: Singapore
Distribution: Debian Sarge/Etch
Posts: 19
Rep:
|
Ok  now I have read your question properly. The output of a command can be added to a file in the same way.
For instance:
ls >> a.txt

|
|
|
All times are GMT -5. The time now is 06:27 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|