Append by line number

i want to append line 1 of file1
to the beginning of line1 of file2 and keep existing txt
i have tried this sed

sed -n '1p' file1 >> file2

but that goes to line 2

example

file1 looks like this

jump

file2 should look like this

jump over

i would to do this by line number as the txt is always different

thanks

file1=file1
file2=file2

file1_line=1
file2_line=1

(( file2_line = file2_line - 1 ))

printf "$file2_line:r !sed -n '$file1_line p' $file1\nj\nw!\n" | ex $file2

hi thanks

forgot to say

i want to do this with sed or awk

file1=file1
file2=file2

file1_line=1
file2_line=1

sed -i ''"$file2_line"' {s/^/'"$(sed -n ''"$file1_line"' p' $file1)"' /}' $file2

hi rdrtx1

i cant get that to work it just hangs in the terminal
nothing happens

Why does it have to be sed or awk? Would this be a homework question? There are forum rules about homework questions.

Andrew

sed or awk
cuz thats what i use on a linux enigma2 box

as for homework nothing to do with homework
im not on any course and im not a student

so can anyone help me with this
thanks

Please become accustomed to provide decent context info of your problem.
It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

With the description and the data given, this

paste -d" " file[12]
jump over

will do what was requested.

Why can't you use paste? It should be a standard Linux command.

This sed script may work with the caveat that I don't guarantee all lines will be pasted (should one file be longer than the other):

printf "%s\n" {a..z} > rightfile
printf "%s\n" {1..26} > leftfile
< rightfile sed 's/\^/\\^/g'  | sed '=;s!^!s^$^ !;s!$!^!'  | sed 'N;s/\n/\t/' > tmpfile
< leftfile sed -f tmpfile
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 h
9 i
10 j
11 k
12 l
13 m
14 n
15 o
16 p
17 q
18 r
19 s
20 t
21 u
22 v
23 w
24 x
25 y
26 z

I've written it so you can type

< file 

and then paste the rest of the line from the first sed .

It's horrible but it works on my Ubuntu system.

Andrew

hi
i cant see how i can ask any different way
i think i made it clear enough

no it wont do what i want as the txt is always different

in post one

i would to do this by line number as the txt is always different

No, you didn't make it clear at all, as you can see by the number of people wildly guessing around what the problem is. Why would the paste proposal NOT fulfill your needs, even when "txt is always different"?
You posted the contents of file1 to be one single word, you didn't bother to post an example of file2; the desired output lets conclude it has one single word as well. Will that always be the case?
Why do you need "to do this by line number" - in post#1 it has been defined to be line 1 from file1 to go to the begin of file 2, i.e. line 1. You don't seem to see your requirements clearly yourself...?

1 Like