Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Not sure on how to turn this input:


into this output:

A apartner
B bpartner
c cpartner

I have this pattern in a 80 line file that needs to be 40 line. Also, how can I enclose each item, in lets say, <il><b>A</b> <i>apartner</i></il>?

share|improve this question
up vote 8 down vote accepted

Using pr from coreutils:

pr -2 -t -l 40 -s' ' $oldfile > $newfile

Add tags using the same pr and sed:

pr -2 -t -l 40 -J -S'</b> <i>' $oldfile | sed 's|^|<il><b>|;s|$|</i></il>|' > $newfile


<il><b>A</b> <i>apartner</i></il>
<il><b>B</b> <i>bpartner</i></il>
<il><b>C</b> <i>cpartner</i></il>
share|improve this answer


If it's not important to use sed or awk then I recommend this as the easiest solution:

First you split the file in two:

head -n 40 file >file1
tail -n 40 file >file2

Then you combine the lines:

paste --delimiters=" " file1 file2

Instead of head and tail you can use sed or awk, of course:

sed -n -e 1,40p combinedfile >file1
sed -n -e 41,80p combinedfile >file2
awk 'NR < 41 {print;}' combinedfile >file1
awk 'NR > 40 {print;}' combinedfile >file2

OK, I just realize: The pure awk solution isn't as complicated as I thought:

awk 'NR < 41 { lines[NR]=$0; next; }; {print lines[NR-40],$0}' combinedfile
share|improve this answer
you can skip creating file1 and file2: paste <(head -40 file) <(tail -40 file ) – mmckinst Jun 12 '13 at 23:06
Simpler and much understandable. Thanks. – mirandalol Jun 20 '13 at 12:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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