problem with cat and echo

problem with cat and echo

am 01.04.2008 20:11:15 von laredotornado

Hi,

I'm using Fedora Core 6 Linux with shell zsh. I have two files a.txt
and b.txt, which I want to concatenate to make a third file, "c.txt".
The only difference is in the new file "c.txt", I would like a new
first line. Sadly, this doesn't work

echo 'first_line' | xargs cat a.txt b.txt > c.txt

What can I do? Thanks, - Dave

Re: problem with cat and echo

am 01.04.2008 20:28:12 von Ed Morton

On 4/1/2008 1:11 PM, laredotornado wrote:
> Hi,
>
> I'm using Fedora Core 6 Linux with shell zsh. I have two files a.txt
> and b.txt, which I want to concatenate to make a third file, "c.txt".
> The only difference is in the new file "c.txt", I would like a new
> first line. Sadly, this doesn't work
>
> echo 'first_line' | xargs cat a.txt b.txt > c.txt
>
> What can I do? Thanks, - Dave

{ echo 'first_line'; cat a.txt b.txt } > c.txt

Re: problem with cat and echo

am 01.04.2008 20:32:09 von Ed Morton

On 4/1/2008 1:44 PM, pk wrote:
> Ed Morton wrote:
>
>
>>{ echo 'first_line'; cat a.txt b.txt } > c.txt
>
>
> I think you need a ";" after "b.txt" }, or use round parenthesis instead.
>

Yes. Thanks.

Ed.

Re: problem with cat and echo

am 01.04.2008 20:37:53 von PK

laredotornado wrote:

> Hi,
>
> I'm using Fedora Core 6 Linux with shell zsh. I have two files a.txt
> and b.txt, which I want to concatenate to make a third file, "c.txt".
> The only difference is in the new file "c.txt", I would like a new
> first line. Sadly, this doesn't work
>
> echo 'first_line' | xargs cat a.txt b.txt > c.txt

A "new first line" is a line to replace a.txt's first line or a completely
new, extra line?

In the latter case:

echo 'first_line' | cat - a.txt b.txt > c.txt

In the former case:

{ echo 'first_line'; tail -n +2 a.txt; } | cat - b.txt > c.txt

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Re: problem with cat and echo

am 01.04.2008 20:44:13 von PK

Ed Morton wrote:

> { echo 'first_line'; cat a.txt b.txt } > c.txt

I think you need a ";" after "b.txt" }, or use round parenthesis instead.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Re: problem with cat and echo

am 01.04.2008 23:27:28 von Chris Mattern

On 2008-04-01, laredotornado wrote:
> Hi,
>
> I'm using Fedora Core 6 Linux with shell zsh. I have two files a.txt
> and b.txt, which I want to concatenate to make a third file, "c.txt".
> The only difference is in the new file "c.txt", I would like a new
> first line. Sadly, this doesn't work
>
> echo 'first_line' | xargs cat a.txt b.txt > c.txt

You don't seem to understand what xargs does. It builds
command lines using its arguments and appending standard
input at the end (by default). This tries to execute the
command line "cat a.txt b.txt first_line", with the output
redirected to c.txt. This is the wrong approach, as cat
doesn't process text in its command line, only file names.
For this to make sense, you would have to have a file
named "first_line" that you wanted to concatenate.
Fortunately, you can tell cat to process standard input as
one of the files to be processed:

echo "first_line" | cat - a.txt b.txt

>
> What can I do? Thanks, - Dave

Stop using xargs and use "-" as an argument to cat to
tell it to use standard input in the concatenation.


--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities

Re: problem with cat and echo

am 01.04.2008 23:29:38 von Chris Mattern

On 2008-04-01, Ed Morton wrote:
>
>
> On 4/1/2008 1:44 PM, pk wrote:
>> Ed Morton wrote:
>>
>>
>>>{ echo 'first_line'; cat a.txt b.txt } > c.txt
>>
>>
>> I think you need a ";" after "b.txt" }, or use round parenthesis instead.
>>
>
> Yes. Thanks.
>
I still think that 'echo "first_line" | cat - a.txt b.txt > c.txt' is
more straightforward and more easily read.

--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities