LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 03-01-2007, 11:40 AM   #1
isra
Member
 
Registered: Jan 2006
Location: Mexico, city
Distribution: DEBIAN, OpenSolaris
Posts: 32

Rep: Reputation: 15
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
 
Old 03-01-2007, 12:11 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
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?
 
Old 03-01-2007, 12:29 PM   #3
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
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
 
Old 03-01-2007, 12:52 PM   #4
isra
Member
 
Registered: Jan 2006
Location: Mexico, city
Distribution: DEBIAN, OpenSolaris
Posts: 32

Original Poster
Rep: Reputation: 15
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.
 
Old 03-05-2007, 06:20 AM   #5
pk2001
LQ Newbie
 
Registered: Feb 2007
Location: Singapore
Distribution: Debian Sarge/Etch
Posts: 19

Rep: Reputation: 0
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.
 
Old 03-05-2007, 06:22 AM   #6
pk2001
LQ Newbie
 
Registered: Feb 2007
Location: Singapore
Distribution: Debian Sarge/Etch
Posts: 19

Rep: Reputation: 0
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

 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to install Wine but can't seem to add lines to source.list Spec4 Linux - Software 5 01-08-2007 03:25 AM
how to add lines to a .conf file richeyc Linux - Hardware 2 04-29-2006 03:25 PM
How can I use a shell script to add and replace lines in a file? abefroman Programming 10 12-27-2005 05:05 PM
More lines to add- XF86Config? fukumdaryl Fedora - Installation 3 02-16-2004 10:33 AM
Add lines of code to files from command line robeb Linux - General 2 06-12-2002 03:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

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