format string output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting format string output
# 1  
Old 11-12-2010
format string output

I need to put the output of the ps -ef command into a string.
echo'n that string must display the output similiar to how we see the output of ps -ef in commandline.

This is the string

message="this is the output of ps command\n\n
`ps -ef`\n\n
Output Complete"

when I echo $message the output should be something like this:

this is the couput of ps command

oracle 23 343 23 .....
oracle 45 453 34
...
...
...

Output Complete

Please let me know
# 2  
Old 11-12-2010
This is not possible. The line breaks and multiple spaces in the "ps" output will be lost.
What do you want to do with $message ? There will no doubt be another way without putting the output from "ps" into an environment variable.

Please also mention what Operating System and version you have and which Shell you are using.
# 3  
Old 11-12-2010
Code:
#!/bin/ksh
IFSsav="$IFS"
IFS="XXXXXXXX"
echo "this is the output of ps command\n\n
`ps -ef`\n\n
Output Complete"
IFS="$IFSsav"

# 4  
Old 11-12-2010
Thanks for checking methyl and anurag...anurag ,that is not what I needed

methyl, $message is fed into a monitor tool so that it can display the content of $message . I'm trying this for both hp-ux 11.11 and sun 5.9 OS, shell is ksh.let me know if there is any other way out.
# 5  
Old 11-12-2010
Try this:
Code:
message="this is the output of ps command

$(ps -ef)

Output Complete"
echo "$message"


Last edited by Scrutinizer; 11-12-2010 at 02:19 PM..
# 6  
Old 11-12-2010
Code:
#!/bin/ksh
IFSsav="$IFS"
IFS="XXXXXXXX"
message="this is the output of ps command\n\n
`ps -ef`\n\n
Output Complete"
echo "$message"
IFS="$IFSsav"

Here message variable will have the formated string.
OR the way Scrutinizer suggested.
# 7  
Old 11-12-2010
Thanks. But the output of $message is not the way I wanted.

echo'n that string must display the output similiar to how we see the output of ps -ef in commandline.

the $(ps -ef) when shown in $message does not show the processes line by line, instead they are in one single line all together....

can awk or sed be helpful here in anyway?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format with output

I have written some scripts that resulted in the table below (Column1 is ITEM, Column2 is Group, Column3 is Category and Column4 is Quantity) but I want the output in another format: Input: K123 X CATA 3 K123 Y CATA 4 K123 Z CATA 2 K123 X CATB 5 K123 Y CATB 2 K123 Z CATB 2 B65 M CATB... (7 Replies)
Discussion started by: aydj
7 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

FORMAT output

Input File Symmetrix ID : 000192601507 Masking View Name : TS00P22_13E_1 Last updated at : 05:10:18 AM on Tue Mar 22,2011 Initiator Group Name : 10000000c960b9cd Host Initiators { WWN : 10000000c960b9cd WWN : 10000000c960b9dd } Port... (1 Reply)
Discussion started by: greycells
1 Replies

4. Shell Programming and Scripting

Output for 'who' in particular format

echo `whoami;echo @;who -ms | cut -f 2 -d "(" | sed "s/)$//"` getting output as : <userid> @ <machinename> Is it possible to get output as : <userid>@<machinename> (9 Replies)
Discussion started by: lalitpct
9 Replies

5. Shell Programming and Scripting

awk: round output or delimit output of arithmatic string

I have a file with the following content. > cat /tmp/internetusage.txt 6709.296322 30000 2/7/2010 0.00I am using the following awk command to calculate a percentage from field 1 and 2 from the file. awk '{ print $1/$2*100 }' /tmp/internetusage.txt This outputs the value "22.3643" as a... (1 Reply)
Discussion started by: jelloir
1 Replies

6. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

7. UNIX for Advanced & Expert Users

Format the Output

Hi- Objective of the task is to print the lines which doesnt have a END statement corresponding to a START statement. Let me know if anyone has a better way of doing is. My Thoughts Have 2 files one having START lines and another having END lines (sorted). And then diff the files to get... (8 Replies)
Discussion started by: lorcan
8 Replies

8. Shell Programming and Scripting

How to format output

Dear all, I have written a program which access database and displays the values returned by the query . There are 10 columns to be displayed in one row. But am ending with 5 lines displayed on 1st line and the next 5 in the 2nd line. Ex : 21608 10-20-2007 148 Al's Appliance... (7 Replies)
Discussion started by: uday542
7 Replies

9. Shell Programming and Scripting

capturing output from top and format output

Hi all, I'd like to capture the output from the 'top' command to monitor my CPU and Mem utilisation.Currently my command isecho date `top -b -n1 | grep -e Cpu -e Mem` I get the output in 3 separate lines.Tue Feb 24 15:00:03 Cpu(s): 3.4% us, 8.5% sy .. .. Mem: 1011480k total, 226928k used, ....... (4 Replies)
Discussion started by: new2ss
4 Replies

10. UNIX for Dummies Questions & Answers

ls output format

below is the output is ls -l -rw-r--r-- 1 tonyt staff 3212 Apr 17 1999 file1 -rw-r--r-- 1 tonyt staff 4541 Mar 3 21:08 file2 why the date format is not the same? (6 Replies)
Discussion started by: tonyt
6 Replies
Login or Register to Ask a Question