-3

I want to combine two text file in a certain fashion as shown below using Linux terminal: Rule is that I add two files such that every line of file 2 comes alternatively except for 6 under which no line should come from file 2 and for 7 , 2 line should come under this from file 2

File 1:

1
2
3
4
5
6
7
8
9
10
11

File 2:

a
b
c
d
e
f
g
h
i
j

Output:

1
a
2
b
3
c
4
d
5
e
6
7
f
g
8
h
9
i
10
j
11
  • 3
    Please add some information what you have tried and where you are stuck. And tell us what are the rules for the combination, I cannot see a simple logic. What is the rule to have c in front of 3 ? – pLumo Apr 15 '19 at 8:14
  • 2
    now 7 is before f? – pLumo Apr 15 '19 at 8:25
  • Yeah..I need to do exactly as above – Akash Ranjan Apr 15 '19 at 8:26
  • I have added the rule that each line from file 2 should come alternatively except for 6 and 7 where no line should come under 6 and 2 line from file 2 should come under 7 – Akash Ranjan Apr 15 '19 at 8:38
  • Please stop adding information to the comments. Go back and edit your question so that it's easy for people to see what you want. – roaima Apr 15 '19 at 14:05
1

Using GNU sed:

$ sed -e '6!RFile 2' -e '7RFile 2' File\ 1
1
a
2
b
3
c
4
d
5
e
6
7
f
g
8
h
9
i
10
j
11
| improve this answer | |
0
$ awk 'NR==FNR{Arr[NR]=$0;next}{print;if(Arr[FNR]){print Arr[FNR]}}' file2 file1
1
a
2
b
3
c
4
d
5
6

read the file2 and keep the values in Array, then start to read the file1 and print along with the file2 values

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.