insert file?

Jacques B. jjrboucher at
Wed Nov 28 16:56:48 UTC 2007

On Nov 28, 2007 10:26 AM, adrian kok <adriankok2000 at> wrote:
> Hi
> Please help how insert `who` in the third line of the
> file
> "head -n 3 file" << `who`
> Thank you

If you are talking about inserting it in the output on the screen then
you could do something like this where file is replaced with the file
you are working on.

head -n 3 file;who;tail -n $(echo "$(wc -l file | cut -d " " -f 1) -3" |bc) file

What I did was use the word count command (wc) to count the number of
lines and then used the cut command to grab only the first field in
the output of the wc command (being the actual number of lines in the
file).  I then used the bc command (a calculator) to substract 3 from
the total number of lines.  Finally the result of that calculation was
used in the tail command to display all but the first 3 lines of the

if you want to insert it in the file itself then one way would be to
redirect the head command to a new file, then double redirect the who
command to the same file to append to it, then double redirect the
tail command to the new file and you are done.  So something like

head -n 3 file >newfile;who>>newfile;tail -n $(echo "$(wc -l file |
cut -d " " -f 1) -3" |bc) file>>newfile

Jacques B.

More information about the fedora-list mailing list