Re: insert file?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Nov 28, 2007 10:26 AM, adrian kok <adriankok2000@xxxxxxxxxxxx> 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
file.

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
this:

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

Jacques B.

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux