Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I try to write script and echo two command at the same line . echo "A" echo "B" How can I pipe above two command at the same line ...
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Posts
    44

    echo two command output in the same line

    Hi,
    I try to write script and echo two command at the same line .
    echo "A"
    echo "B"

    How can I pipe above two command at the same line in text file .
    So, in the output text file , you can see below ???
    Code:
    A     B
    not
    Code:
    A
    B
    Any sugggestion ???

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    $echo "a" ; echo "b"
    a
    b
    $ echo -n "a" ; echo "b"
    ab
    Does that help ?
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Just Joined!
    Join Date
    Aug 2009
    Posts
    44
    Quote Originally Posted by Lakshmipathi View Post
    Does that help ?
    acutally, I try to execute the ps command two time and output to text file at the same line .

    ps -o %cpu,%mem,lstart,args,comm,cputime,pid,rss,vsz -p 1

    How can I do that ??

  4. #4
    Just Joined!
    Join Date
    Dec 2010
    Posts
    16
    I am not sure whether I understand your question correct. Do you really want to have the output of ps twice and in one long line?
    Then do:

    Code:
    ps -o %cpu,%mem,lstart,args,comm,cputime,pid,rss,vsz -p 1 | tee - | tr -d '\n' > output_ps
    If you want to have the output of ps only once, remove | tee -
    Last edited by Lahntaler; 01-25-2011 at 11:09 AM.

  5. #5
    Just Joined!
    Join Date
    Dec 2010
    Posts
    16
    If you want to have the output of ps both on stdout and a file, do:

    Code:
    ps -o %cpu,%mem,lstart,args,comm,cputime,pid,rss,vsz -p 1 | tee -a output_ps
    tee with the option -a appends to output_ps.
    tee overwrites output_ps if the option -a is not used.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...