how to read a certain column from the status result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to read a certain column from the status result
# 1  
Old 06-01-2010
how to read a certain column from the status result

I am using this script to get the status of the running process
Code:
VAR=$(ps -ef | grep batch_proc_x | grep -v grep)
echo $VAR

now it returns this

Code:
splgwin 13195 13100  0 14:13:13 pts/tb    0:00 /usr/bin/ksh ./batch_proc_x.sh

now is there a way to read that time 14:13:13 directly from VAR?

I am doing this to get the time
Code:
        FTP_HOUR=$(echo $VAR|cut -c22-23)
        FTP_MIN=$(echo $VAR|cut -c25-26)
        FTP_SEC=$(echo $VAR|cut -c28-29)

but this works some time and some time it doesn't. Looks like the width of the result is not always same. so when I am doing -c22 it some times reads from the second digit like 4: instead of 14.
# 2  
Old 06-01-2010
Code:
FTP_HOUR=`echo $VAR | awk '{print $5;}' | awk -F: '{print $1;}'`
FTP_MIN=`echo $VAR | awk '{print $5;}' | awk -F: '{print $2;}'`
FTP_SEC=`echo $VAR | awk '{print $5;}' | awk -F: '{print $3;}'`

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 06-01-2010
Code:
echo $VAR | awk ' { print $5 } ' | IFS=":" read FTP_HOUR FTP_MIN FTP_SEC

This User Gave Thanks to anbu23 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Add column and multiply its result to all elements of another column

Input file is as follows: 1 | 6 2 | 7 3 | 8 4 | 9 5 | 10 Output reuired (sum of the first column $1*$2) 1 | 6 | 90 2 | 7 | 105 3 | 8 | 120 4 |9 | 135 5 |10 | 150 Please enclose sample input, sample output, and code... (5 Replies)
Discussion started by: Sagar Singh
5 Replies

2. Shell Programming and Scripting

Read first column and count lines in second column using awk

Hello all, I would like to ask your help here: I've a huge file that has 2 columns. A part of it is: sorted.txt: kss23 rml.67lkj kss23 zhh.6gf kss23 nhd.09.fdd kss23 hp.767.88.89 fl67 nmdsfs.56.df.67 fl67 kk.fgf.98.56.n fl67 bgdgdfg.hjj.879.d fl66 kl..hfh.76.ghg fl66... (5 Replies)
Discussion started by: Padavan
5 Replies

3. Shell Programming and Scripting

Counting specific column and add result in output

Hi all, I have a quick question: I have a 4 column tab-separated file. I want to count the number of times each unique value in column 2 appears and add that number in a 5th column. I have the following input file: waterline-n below-sheath-v 14.8097 A dock-n below-sheath-v ... (4 Replies)
Discussion started by: owwow14
4 Replies

4. Windows & DOS: Issues & Discussions

Read command result as variable

Hi all, Is there a simple way to read a command output as a variable? I've running a batch file to do: attrib.exe * | find /c /v "" >filecount.txt but rather than write it to the txt file I'd like to read the total in as a variable to pass to the rest of the bat file... Any help much... (1 Reply)
Discussion started by: Grueben
1 Replies

5. UNIX for Dummies Questions & Answers

how to read how many times same result occurs?

Is there a way to read how many times each result occurs in a list, say the list.txt has the results: a c d a f c a d e and I need to know how many times each of them occurs such as : a=3 c=2 ..etc. (5 Replies)
Discussion started by: Iifa
5 Replies

6. Shell Programming and Scripting

Filter the column and print the result based on condition

Hi all This is my output of the some SQL Query TABLESPACE_NAME FILE_NAME TOTALSPACE FREESPACE USEDSPACE Free ------------------------- ------------------------------------------------------- ---------- --------- ---------... (2 Replies)
Discussion started by: jhon
2 Replies

7. Shell Programming and Scripting

read a file in shell and put result in a line

Hi All, I have a to read a file and put the result in one line. The i am reading from contain the data like below. 1 signifies the beging of the new line. (6 Replies)
Discussion started by: lottiem
6 Replies

8. Shell Programming and Scripting

printing in certain column based on some result

hii every one can anybody help me writing shell script with this, i have a file ... amit arun vivek and i want to read something from the user and print next to amit or arun in certain column.. like amit 23-wall street 2000 arun 34343 vivek 4758 is... (6 Replies)
Discussion started by: kumar_amit
6 Replies

9. Shell Programming and Scripting

urgent -read exit status

i have written a shell script that invokes main class of a java prg. the java prg does a System.exit(0) or (1) based on condition. how can i read or check the status in unix.... (4 Replies)
Discussion started by: iamcool
4 Replies
Login or Register to Ask a Question