Click to See Complete Forum and Search --> : copying multiple files into one file


HelpPlease
12-09-2003, 12:43 PM
:( Help PLEASE...........i need to copy three files into one file, but I don't know the linux coding to make the shell.


HELP HELP HELP
ASAP
thanks:confused:

bradfordgd
12-09-2003, 12:52 PM
I suppose it depends where the 3 files are located and how you need to copy them. Are they all in the same directory? Are they the only 3 files in the directory? If they are then something like this would work;

# cat * >> newfile

Are they in different directories with different names? Do they need to be copied into the new file in any specific order? If so try something like this;

1. Create a file with the full name of your 3 files (i.e. use vi or some thing like "cat "/file1 /file2 /file3" > file_list.
2. run this command

# for files in `cat file_list`
do
cat $file >> newfile
done

Hope that helps. If not, maybe a little more info on what you are trying to accomplish would help to get you going in the right direction.

HelpPlease
12-09-2003, 01:07 PM
I have 3 files in one directory. i would like them to be copied into the single file(not in a directory) in the order inwhich the files are...........example: file1.txt, file2.txt file3.txt are in directory called ALL...........i want those files to be copied into a file called TOGETHER.txt..............if i can get that to work then i would like to know how to delete multiple files at one time.....example all txt. in a specific directory.

thanks for replying:)

Ok...........i created a shell called last.sh but i get.............

$ vi last.sh

"last.sh" [Incomplete last line] 8 lines, 136 characters
# last.sh^M
#!/bin/sh^M
if [-f $4] ; then ^M
rm -f $4 ^M
touch $4^M
cat $1 $2 $3 >> $4^M
then do sh <file> file1 file2 file3 <target file>^M
fi
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"last.sh" [Incomplete last line] 8 lines, 136 character
There is something wrong in the coding because when i do...........
$ sh last.sh
last.sh: syntax error at line 7: `then' unexpected
[~]
$ ./last.sh
bash: ./last.sh: Permission denied
[~]
I don't know whats wrong

voidinit
12-10-2003, 03:13 AM
Ok, then cd to all.

you@yourhost:~$>cd all
you@yourhost:~/all$>ls
file1.txt file2.txt file3.txt
you@yourhost~/all$>ls -1 > file_list.txt
you@yourhost~/all$>cat file_list.txt
file1.txt
file2.txt
file3.txt
you@yourhost:~/all$>touch together.txt
you@yourhost:~/all$>for i in `cat file_list.txt`; do cat $i >> together.txt; done
you@yourhost:~/all$>cat together.txt
contents of file1.txt.......
contents of file2.txt.......
contents of file3.txt.......

What you just did created a text file with a complete listing of the directory /all in it. This listing had one filename on each line of the text file. Then you created a new, empty file with the touch command. Then you looped through the directory listing (file_list.txt) pulling one filename at a time out of it and assigning that filename to $i. Then you concatenated (cat) the files together, appending one right after the other.

JThundley
12-10-2003, 03:26 AM
If you just need to move or back up the files, put them in an archive:

tar cvzf files.tar.gz file1.txt file2.txt file3.txt

That way you can get your files out easier.