LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-09-2003, 02:15 PM   #1
HelpPlease
LQ Newbie
 
Registered: Dec 2003
Posts: 1

Rep: Reputation: 0
Unhappy copy multiple files into one file


HELP HELP HELP.......i'm trying to copy thre files: file1.txt file2.txt file3.txt..........

file1.txt
jane doe 12/25/80
john doe 09/05/86
jenny doe 06/30/59
james doe 08/21/59


file2.txt
Address: 5555 Whitby Rd. Baltimore,MD 21206


file3.txt
Phone Number: (410)555-5050


into a file called together.txt..............i did:



$ cat file1.txt file2.txt file3.txt >> together.txt

which produced:
jane doe 12/25/80
john doe 09/05/86
jenny doe 06/30/59
james doe 08/21/59Adress: 5555 Whitby Rd. Baltimore,MD 21206Phone Number: (410)555-5050
i need to write a .sh script that implements this but i don't know how?......
i thought that after i write the shell and save the command should be: $ ./all.sh together.txt file1.txt file2.txt file3.txt..........and then i cat together.txt........but i'm not sure.
and how do i get the files to copy on separate lines?
 
Old 12-09-2003, 02:34 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Your problem is that the files don't end
with a CarriageReturn ...

Btw, homework questions aren't allowed ;)


Cheers,
Tink
 
Old 12-09-2003, 02:36 PM   #3
Skyline
Senior Member
 
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104

Rep: Reputation: 45
This is in bash and does soemthing "similar".. modify to suit..

Code:
#!bin/bash

y() { echo -e "\n" >> $compilation_file; }
z() { echo -e "\n\n" >> $compilation_file; }

echo - "Please type the path to the compilation file :"
read compilation_file
echo "Please type the path of the original files that are going to make up the compilation file with a space between each path/filename :"
read -a original_files

for i in ${original_files[*]}
do
echo "$i" >> $compilation_file ; y
cat $i >> $compilation_file ; z
done
..... and if you dont want the filenames in aswell, just the spacing between files and the content then take out these 2 lines:

y() { echo -e "\n" >> $compilation_file; }
echo "$i" >> $compilation_file ; y


Last edited by Skyline; 12-09-2003 at 02:52 PM.
 
  


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
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 8 02-07-2014 07:56 PM
How do I copy multiple files Leary664 Linux - General 18 09-06-2005 02:58 AM
search and copy multiple files NiallC Programming 2 04-29-2005 04:40 AM
Multiple file copy james.farrow Linux - Newbie 8 08-17-2004 08:01 AM
find and copy files into multiple directories avargas22 Linux - Newbie 2 04-01-2004 11:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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