Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

paster but ignore first line of dest file

17 views
Skip to first unread message

dxt...@gmail.com

unread,
Jun 25, 2015, 1:45:15 PM6/25/15
to
Hello,

Is there a way with paste to ignore the first line when pasting to std out or to a file.
ie: I have this:

$ cat fn1
Days: Mon Tues Wed Thurs Fri
10

I need to paste a value ( 12) from the file (fn), into the above file so I end up with:
Days: Mon Tues Wed Thurs Fri
10 12

But I get, the '12' appended to the end of the first line:

$ cat fn
tues 12


$ cat fn| cut -f2|paste fn1 -
Days: Mon Tues Wed Thurs Fri 12
10

I am stuck with using paste on this one

thanks
DT


Janis Papanagnou

unread,
Jun 25, 2015, 2:33:24 PM6/25/15
to
Do you need to do it with paste? - If not...

With awk:

awk 'NR==2 {x=$1; getline <"fn"; $0=x" "$2};1' fn1

With shell:

{ read a; read b ;} <fn1 ; read c d <fn
printf "%s\n" "$a" "$b $d"


Janis

>
> thanks
> DT
>
>
>

Stephane Chazelas

unread,
Jun 25, 2015, 3:25:11 PM6/25/15
to
2015-06-25 10:45:12 -0700, dxt...@gmail.com:
[...]
[...]

Using process substitution (zsh, bash, some ksh):

(head -n1; paste - <(cut -f2 < fn2)) < fn1

(assumes fn1 is seekable and head is POSIX conformant).

--
Stephane

Ben Bacarisse

unread,
Jun 25, 2015, 5:09:44 PM6/25/15
to
dxt...@gmail.com writes:

> Is there a way with paste to ignore the first line when pasting to std
> out or to a file.

There may be another way...

> ie: I have this:
>
> $ cat fn1
> Days: Mon Tues Wed Thurs Fri
> 10
>
> I need to paste a value ( 12) from the file (fn), into the above file
> so I end up with:
> Days: Mon Tues Wed Thurs Fri
> 10 12
>
> But I get, the '12' appended to the end of the first line:
>
> $ cat fn
> tues 12
>
>
> $ cat fn| cut -f2|paste fn1 -
> Days: Mon Tues Wed Thurs Fri 12
> 10

If you don't mind a stray tab you can *add* a line:

sed -e 'i\\' fn | cut -f2 | paste fn1 -

and you can get sed to do the job of the cut command if you like:

sed -e 'i\\' -e 's/.*\t//' fn | paste fn1 -

(you need a sed that understands \t or you can use an actual tab).

--
Ben.

Kenny McCormack

unread,
Jun 25, 2015, 5:24:07 PM6/25/15
to
In article <874mlvv...@bsb.me.uk>,
Ben Bacarisse <ben.u...@bsb.me.uk> wrote:
>dxt...@gmail.com writes:
>
>> Is there a way with paste to ignore the first line when pasting to std
>> out or to a file.
>
>There may be another way...

If you are allowed any other tools, then this problem becomes moot, since
you'd just do it in AWK (or Perl or Python or ...).

The problem is only interesting if you are literally limited to using
"paste" - and the OP was very explicit that this *is* the key requirement.

--
Genesis 2:7 And the LORD God formed man of the dust of the ground, and
breathed into his nostrils the breath of life; and man became a living soul.

Janis Papanagnou

unread,
Jun 25, 2015, 6:36:57 PM6/25/15
to
On 25.06.2015 23:24, Kenny McCormack wrote:
> In article <874mlvv...@bsb.me.uk>,
> Ben Bacarisse <ben.u...@bsb.me.uk> wrote:
>> dxt...@gmail.com writes:
>>
>>> Is there a way with paste to ignore the first line when pasting to std
>>> out or to a file.
>>
>> There may be another way...
>
> If you are allowed any other tools, then this problem becomes moot, since
> you'd just do it in AWK (or Perl or Python or ...).

tl;dr
It's simple; with paste *alone* one cannot do what the OP wants.


We'd either need additional tools or another approach. It also makes
no sense to ask for a solution where paste is a part of; just add to
any working solution: paste fn fn1 >/dev/null (useless use of paste).

>
> The problem is only interesting if you are literally limited to using
> "paste" - and the OP was very explicit that this *is* the key requirement.

The OP was also using cat (UUOC), so I'd assume it's just ignorance;
we often hear "How can I achieve XYZ with ABC ?", just because some
folks don't know the many options available. - Why use any external
tool if one can do it (effectively and efficiently) in shell alone.

Janis

Ben Bacarisse

unread,
Jun 25, 2015, 6:41:59 PM6/25/15
to
gaz...@shell.xmission.com (Kenny McCormack) writes:

> In article <874mlvv...@bsb.me.uk>,
> Ben Bacarisse <ben.u...@bsb.me.uk> wrote:
>>dxt...@gmail.com writes:
>>
>>> Is there a way with paste to ignore the first line when pasting to std
>>> out or to a file.
>>
>>There may be another way...
>
> If you are allowed any other tools, then this problem becomes moot, since
> you'd just do it in AWK (or Perl or Python or ...).
>
> The problem is only interesting if you are literally limited to using
> "paste" - and the OP was very explicit that this *is* the key requirement.

Which is why I used paste.

I don't think a key requirement was to use *only* paste. Surely the OP
knows that selecting and pasting only the second field is not going to
possible with paste? The OP seemed content with the cut -f2 for that
part.

Anyway, with awk and other solutions already posted I thought it worth
showing another point of view.

--
Ben.

Barry Margolin

unread,
Jun 25, 2015, 9:40:44 PM6/25/15
to
In article <mmhvq5$gqr$1...@news.m-online.net>,
The word for this is "XY Problem".

http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem

Although the OP did describe the higher-level problem. He just ended it
with "I'm stuck with using paste on this" -- so it seems like he has
some external constraint that requires this particular solution. Maybe
it's a coding puzzle?

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Janis Papanagnou

unread,
Jun 26, 2015, 6:27:07 AM6/26/15
to
On 26.06.2015 03:40, Barry Margolin wrote:
[...]
Yes, thanks.

>
> Although the OP did describe the higher-level problem. He just ended it
> with "I'm stuck with using paste on this"

Oh, (being a non-native speaker) I interpreted that as: "I tried using
paste [because I thought it was an appropriate tool] and now I'm stuck."

> -- so it seems like he has
> some external constraint that requires this particular solution.

(What [sensible] contraint could that be?)

> Maybe it's a coding puzzle?

(The OP's concrete data don't look like a puzzle.)

Janis

Andy Walker

unread,
Jun 26, 2015, 7:32:59 AM6/26/15
to
On 26/06/15 11:27, Janis Papanagnou wrote:
> Oh, (being a non-native speaker) I interpreted that as: "I tried using
> paste [...] and now I'm stuck."
^^^^^ ^^^^^
Very good! Esp for a non-native speaker.

--
Andy Walker,
Nottingham.

Barry Margolin

unread,
Jun 26, 2015, 7:58:00 AM6/26/15
to
In article <mmjd95$fan$1...@speranza.aioe.org>,
Andy Walker <a...@cuboid.co.uk> wrote:

> On 26/06/15 11:27, Janis Papanagnou wrote:
> > Oh, (being a non-native speaker) I interpreted that as: "I tried using
> > paste [...] and now I'm stuck."
> ^^^^^ ^^^^^
> Very good! Esp for a non-native speaker.

Indeed, when I first read the OP, that was how I interpreted it. But
it's not a normal way to say that, it seems like something only a
non-native speaker would write. The rest of the post was pretty good
English.

Kenny McCormack

unread,
Jun 26, 2015, 12:48:56 PM6/26/15
to
In article <barmar-BB6267....@88-209-239-213.giganet.hu>,
Barry Margolin <bar...@alum.mit.edu> wrote:
>In article <mmjd95$fan$1...@speranza.aioe.org>,
> Andy Walker <a...@cuboid.co.uk> wrote:
>
>> On 26/06/15 11:27, Janis Papanagnou wrote:
>> > Oh, (being a non-native speaker) I interpreted that as: "I tried using
>> > paste [...] and now I'm stuck."
>> ^^^^^ ^^^^^
>> Very good! Esp for a non-native speaker.
>
>Indeed, when I first read the OP, that was how I interpreted it. But
>it's not a normal way to say that, it seems like something only a
>non-native speaker would write. The rest of the post was pretty good
>English.

Agreed (that there is plenty room for ambiguity).

FWIW, I interpreted it (the word "stuck") as meaning "required".

But I realized later on, after thinking about this thread, that it could
also be interpreted in the sense of "stymied".

--
- Since the shootings on Friday, the ultra-defensive [maybe wrongly
- hyphenated, but that would be fitting] Roy "News" LIEberman has posted
- at least 90 times, and almost every single post is about his obsessive
- knee-jerk loonball [wacko] gun politics. How much longer before the
- authorities [police] finally disable the trip wires and confiscate the
- arsenal in his St. Louie hovel?

So true. So true.

0 new messages