 |
 |
 |
 |
| Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum. |

31st May 2012, 02:50 AM
|
 |
Registered User
|
|
Join Date: Oct 2005
Location: Central Michigan
Age: 63
Posts: 189

|
|
Concatenating files
I have several text files that I want to append to each other into a single larger file. What is the correct method for doing this?
__________________
Martyn Griffin
|

31st May 2012, 03:03 AM
|
 |
Registered User
|
|
Join Date: Oct 2006
Location: Richmond BC Canada
Posts: 43

|
|
|
Re: Concatenating files
Take a look at cat (see 'man cat'). It will handle multiple files and copy them to an output file in the order in which the input files are specified.
|

31st May 2012, 03:03 AM
|
 |
Registered User
|
|
Join Date: Oct 2005
Location: Central Michigan
Age: 63
Posts: 189

|
|
|
[SOLVED] Concatenating files
Sorry about that, another brain f**t happened.
Seems obvious now that the cat command is what I want!!!
__________________
Martyn Griffin
|

31st May 2012, 05:00 PM
|
|
Official Gnome 3 Sales Rep. (and Adminstrator)
|
|
Join Date: Jul 2011
Location: Leamington Spa, UK
Age: 30
Posts: 1,707

|
|
|
Re: Concatenating files
cat is probably one of the most abused commands in Unix, rarely used for its intended purpose, and often used completely unnecessarily...
|

31st May 2012, 05:35 PM
|
 |
Registered User
|
|
Join Date: Mar 2009
Location: Lancaster, UK
Posts: 883

|
|
|
Re: Concatenating files
Quote:
Originally Posted by Gareth Jones
cat is probably one of the most abused commands in Unix, rarely used for its intended purpose, and often used completely unnecessarily... 
|
Am i not meant to write scripts with it?
|

31st May 2012, 10:42 PM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 640

|
|
|
Re: Concatenating files
Quote:
Originally Posted by Adunaic
Am i not meant to write scripts with it?
|
Don't worry about it, use cat however you need to in scripts or from the command line.
---------- Post added at 02:42 PM ---------- Previous post was at 02:40 PM ----------
Quote:
Originally Posted by Gareth Jones
cat is probably one of the most abused commands in Unix, rarely used for its intended purpose, and often used completely unnecessarily... 
|
Using cat unnecessarily, or not for it's intended purpose must be because those who claim to know how to use cat don't tell others ...
Hey, I see this forum code assumed I wanted to just make a single post, even if I wanted two separate replies.
.
__________________
======
Doug G
======
|

31st May 2012, 11:11 PM
|
 |
Registered User
|
|
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300

|
|
|
Re: Concatenating files
I suspect Gareth is just saying that a lot of times ppl insert an extra cat in a command sequence where proper I/O redirection with '<' and '>' etc would do as will with one less process. silly things like;
grep " / " /etc/fstab | cat >myrootmount.txt
vs
grep " / " /etc/fstab >myrootmount.txt
There is no magical knowledge about cat. It's one of the simplest utilities out there. I takes a list of filenames from its arglist, opens each in order, and copies their content to stdout. If there is no filename in the arglist, then it copies stdin to stdout (which is usually superfluous).
Old cat (decades ago) only had a '-v' option to print non-printable characters in some decent mode.
Modern (GNU) cat additionally has options to delete blank lines or to number output lines.
So a good reason to use cat is to copy MULTIPLE files to a pipe(stdout) or to view the content of a short text file. It to perform the trivial text processing it supports (line numbers, conversion of unprintables) Frankly 'less' has better utility for text viewing.
Bad reasons are -
- to redirect stdin to stdout (pointless)
- copy a single file to a pipe (use redirection instead)
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Last edited by stevea; 31st May 2012 at 11:26 PM.
|

31st May 2012, 11:29 PM
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 4,978

|
|
|
Re: Concatenating files
A typical misuse of cat. Note that this isn't horrible (especially with a small file) but it's the sort of thing that will happen when someone who is a beginner helps another beginner.
cat myfile|grep testing
A more proper way to do it would be
grep testing myfile
That's a really simple example, but it's the sort of thing that happens when one is learning---they think that they have to cat the file to grep something.
http://partmaps.org/era/unix/award.html#uucaletter might be fun reading. (relatively short)
|

31st May 2012, 11:48 PM
|
 |
Registered User
|
|
Join Date: May 2010
Location: Midwest USA
Posts: 370

|
|
|
Re: Concatenating files
Quote:
Originally Posted by smr54
but it's the sort of thing that will happen when someone who is a beginner helps another beginner.
That's a really simple example, but it's the sort of thing that happens when one is learning---they think that they have to cat the file to grep something.
|
I think the reason that happens is that some Linux books for beginners use the first example as an example of how to use pipes and grep in a basic manner. I've used the first one many many times...until I was told that grep can grep files directly as well as accepting pipes and redirection.
CronoCloud
|

31st May 2012, 11:59 PM
|
 |
Registered User
|
|
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300

|
|
|
Re: Concatenating files
Well tho' these abuses of cat (where is the ASPCA on this?) demonstrate a poor understanding of bash pipe redirections, they aren't harmful in non-production code. It does expose one's noob-ness but that's no fault.
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
|

1st June 2012, 05:38 PM
|
 |
Registered User
|
|
Join Date: Oct 2005
Location: Central Michigan
Age: 63
Posts: 189

|
|
[CLOSED] Concatenating files
I mean NO OFFENSE to anyone on this thread, but the correct answer to the original query came on the very first reply. I just can't help thinking that all the efforts given after that point could have been better directed at solving the other hundreds (thousands?) of outstanding problems folks have posted.
Could the moderator please 'close' this thread?
And again, I really do thank all the members who take their time to help poor slobs like myself!
__________________
Martyn Griffin
|

1st June 2012, 07:24 PM
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 4,978

|
|
|
Re: Concatenating files
Note that as the thread originator, you can click the thread tools and mark it solved, though this won't close it.
It's usually better to PM a mod with a request like that, as they're pretty busy (especially during the first week or so of a release) and may not see your request--you can go the main forum page, click the forums link at top, and it will then, at the bottom of that page, show you who is on line--mods are in boldface. At that point, you can, if you wish, give them a quick PM with a link to the thread, and ask them to close it.
This is the page I mean.
http://forums.fedoraforum.org/?
At this exact moment, it looks as if there's only one moderator on line.
|

1st June 2012, 08:28 PM
|
 |
Registered User
|
|
Join Date: Nov 2006
Location: Detroit
Posts: 4,616

|
|
|
Re: Concatenating files
Quote:
Originally Posted by smr54
A typical misuse of cat.
cat myfile|grep testing
|
Yeah, that's the one that bugs me the most. C'mon, people, save the cats!
The best use of cat I've seen is for adding a line to the beginning of a file:
Code:
$ cat file.txt
This is line 2.
This is line 3.
$ echo "This is line 1." | cat - file.txt
This is line 1.
This is line 2.
This is line 3.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 21:54 (Tuesday, 21-05-2013)
|
|
 |
 |
 |
 |
|
|