FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 11-28-2007, 02:26 PM
adrian kok
 
Default insert file?

Hi

Please help how insert `who` in the third line of the
file

"head -n 3 file" << `who`

Thank you

Send instant messages to your online friends http://uk.messenger.yahoo.com

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-28-2007, 02:47 PM
Frank Cox
 
Default insert file?

On Wed, 28 Nov 2007 23:26:25 +0800 (CST)
adrian kok <adriankok2000@yahoo.com.hk> wrote:

> Please help how insert `who` in the third line of the
> file

man sed

--
MELVILLE THEATRE ~ Melville Sask ~ http://www.melvilletheatre.com

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-28-2007, 03:21 PM
"Mikkel L. Ellertson"
 
Default insert file?

Frank Cox wrote:
> On Wed, 28 Nov 2007 23:26:25 +0800 (CST)
> adrian kok <adriankok2000@yahoo.com.hk> wrote:
>
>> Please help how insert `who` in the third line of the
>> file
>
> man sed
>
I think he wanted to insert the output of the who command in the
file. It that is the case, then it gets a bit more complicated,
because you are trying to insert multiple lines.

You could do something like:

who | sed -i -e2r/dev/stdin <file name>

Mikkel
--

Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-28-2007, 03:28 PM
"Mikkel L. Ellertson"
 
Default insert file?

Mikkel L. Ellertson wrote:
> Frank Cox wrote:
>> On Wed, 28 Nov 2007 23:26:25 +0800 (CST)
>> adrian kok <adriankok2000@yahoo.com.hk> wrote:
>>
>>> Please help how insert `who` in the third line of the
>>> file
>> man sed
>>
> I think he wanted to insert the output of the who command in the
> file. It that is the case, then it gets a bit more complicated,
> because you are trying to insert multiple lines.
>
> You could do something like:
>
> who | sed -i -e2r/dev/stdin <file name>
>
I forgot to add that using the -i will change the original file. If
you want to create a new file, you could use:

who | sed -e2r/dev/stdin <file name> > <new file>

Mikkel
--

Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-28-2007, 03:56 PM
"Jacques B."
 
Default insert file?

On Nov 28, 2007 10:26 AM, adrian kok <adriankok2000@yahoo.com.hk> 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@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-28-2007, 04:23 PM
inode0
 
Default insert file?

On Nov 28, 2007 9:26 AM, adrian kok <adriankok2000@yahoo.com.hk> wrote:
> Hi
>
> Please help how insert `who` in the third line of the
> file
>
> "head -n 3 file" << `who`

$ ed -s foo <<EOF
> 3r !who
> wq
> EOF
$

John

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-28-2007, 05:00 PM
adrian kok
 
Default insert file?

Thank you

Additional question.

When I have error in the console, but can't get from
the log

Can I capture an error to insert the file, no need to
re-type it?

Thank you


--- "Mikkel L. Ellertson" <mikkel@infinity-ltd.com>
wrote:

> Frank Cox wrote:
> > On Wed, 28 Nov 2007 23:26:25 +0800 (CST)
> > adrian kok <adriankok2000@yahoo.com.hk> wrote:
> >
> >> Please help how insert `who` in the third line of
> the
> >> file
> >
> > man sed
> >
> I think he wanted to insert the output of the who
> command in the
> file. It that is the case, then it gets a bit more
> complicated,
> because you are trying to insert multiple lines.
>
> You could do something like:
>
> who | sed -i -e2r/dev/stdin <file name>
>
> Mikkel
> --
>
> Do not meddle in the affairs of dragons,
> for thou art crunchy and taste good with Ketchup!
>
> > --
> fedora-list mailing list
> fedora-list@redhat.com
> To unsubscribe:
https://www.redhat.com/mailman/listinfo/fedora-list


Send instant messages to your online friends http://uk.messenger.yahoo.com

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-28-2007, 05:15 PM
"Jacques B."
 
Default insert file?

On Nov 28, 2007 1:00 PM, adrian kok <adriankok2000@yahoo.com.hk> wrote:
> Thank you
>
> Additional question.
>
> When I have error in the console, but can't get from
> the log
>
> Can I capture an error to insert the file, no need to
> re-type it?
>
> Thank you
>

You can redirect errors using 2>. If you want to append, then 2>>.

For example if you did the ls command below of a directory that had
files one.txt, two.txt and three.txt:

ls one.txt two.ttx three.txt

you will get an error for two.ttx.

You can redirect that using 2>
ls one.txt two.ttx three.txt 2>/dev/null
will redirect errors to /dev/null while stdout will still display to the screen.

ls one.txt two.ttx three.txt 2>lserrors.txt
will redirect errors to the file lserrors.txt while stdout will still
display to the screen.

ls one.txt two.ttx three.txt >goodfiles.txt 2>lserrors.txt
will redirect the errors to lserror.txt and will redirect the
successful part of the command to goodfiles.txt therefore you will
have no output to stdout.

Jacques B.

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-28-2007, 06:53 PM
"Mikkel L. Ellertson"
 
Default insert file?

adrian kok wrote:
> Thank you
>
> Additional question.
>
> When I have error in the console, but can't get from
> the log
>
> Can I capture an error to insert the file, no need to
> re-type it?
>
If you have gpm running, you can use the mouse to cut and past the
message. (man gpm) If it is in an x-terminal, you have the same
options. gterm had an edit tab that lets you copy the highlighted
text. You can then past it into e-mail or a file.

As others have indicated, if you expect an error, you can re-direct
the standard error output to a file. The cut/past method helps with
unexpected error messages.

Mikkel
--

Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-28-2007, 06:56 PM
Alan Cox
 
Default insert file?

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

( head -n3 file; who; tail +3 file) > newfile 2> errors

Much easier

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 

Thread Tools




All times are GMT. The time now is 06:44 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org