How to script / command this in UNIX?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to script / command this in UNIX?
# 8  
Old 09-03-2015
***removing confidential info***

Last edited by aixusrsys; 09-03-2015 at 03:06 AM..
# 9  
Old 09-03-2015
So try:
Code:
awk '
/Application State/ {
	c[$0]++
	if(length($0) > m)
		m = length($0)
}
END {	for(i in c)
		printf("%-*s   : total = %02d\n", m, i, c[i])
}' 1.txt

which with your given sample produces:
Code:
  Application State :      Normal       : total = 03
  Application State :      Pending      : total = 01
  Application State :      Terminated   : total = 01

This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 09-03-2015
Quote:
Originally Posted by Don Cragun
So try:
Code:
awk '
/Application State/ {
    c[$0]++
    if(length($0) > m)
        m = length($0)
}
END {    for(i in c)
        printf("%-*s   : total = %02d\n", m, i, c[i])
}' 1.txt

which with your given sample produces:
Code:
  Application State :      Normal       : total = 03
  Application State :      Pending      : total = 01
  Application State :      Terminated   : total = 01


Thanks works gr8 !
# 11  
Old 09-03-2015
With the latest example you posted, this is what I get:

Code:
awk '/Application State/ {app[$NF]++} END{for(a in app) printf "Application State : %-10s : total = %02d\n", a, app[a]}' aixusrsys.file

Code:
Application State : Normal     : total = 03
Application State : Terminated : total = 01
Application State : Pending    : total = 01


Last edited by Aia; 09-03-2015 at 03:24 AM.. Reason: Post output on its own code tags
# 12  
Old 09-03-2015
I'm very glad that we finally got something to work for you...

Note that the data you posted in message #8 (and deleted 37 minutes later) did not look anything like the data you included in posts #1 and #3. Leading spaces make a difference. Having Application State : instead of Application States : makes a difference. Having six spaces between the colon and the state instead of one space makes a difference.

You don't have to show us confidential data to get our help, but you do need to show us representative data. The commands you said you used in post #3 would have produced absolutely no output (just like Aia's awk script and my awk script) when given your real data instead of the data you showed us in post #1.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using UNIX command in perl script.

I wish to know if there is any limitation in using unix commands in perl script or it is just we should avoid using them in our perl script. For e.g Below is the command to get the recent file in a dir.: $lcsvFile = `cd "$l_inputfilepath";ls -1t *.CSV|tail -1` Is there any harm in coding... (1 Reply)
Discussion started by: Devesh5683
1 Replies

2. UNIX for Dummies Questions & Answers

Execute a command in different directory through Unix Script

Hi Gurus, I have the below requirement, Execute an unix script which will pick the latest file from the archive directory and do a grep (on multiple patterns) on that file. processingDir="/usr/apps/irdc/informatica/spsf_sales/TgtFiles/ARCHIVE" filename = 'ls Check* | sort -n -k 2 |... (6 Replies)
Discussion started by: diva_thilak
6 Replies

3. Shell Programming and Scripting

Unix Script or command Needed

Hi, I am new to Shell Scripting. I need to pick the files from one directory and place them in another directory based on time stamp.It should pick the files if the files is not accessed for 1 hour. Can any one please help me how to work on this. Thanks in Advance. Regards, Prakash (1 Reply)
Discussion started by: kvrprakash
1 Replies

4. Shell Programming and Scripting

UNIX script / Command >>> in one line

Hi Experts, Basically I am a SAP programmer. I don't know much about UNIX. But I got a situation, need to use UNIX script /command in my programming. I searched the forum and found the below code. I would like to pass the below UNIX script in my programming code. But my programming will... (1 Reply)
Discussion started by: rbadveli
1 Replies

5. Shell Programming and Scripting

cp command not working in script for non unix file

Piece of code in sh file ------------------------ echo "lalit test bef" which cp cp $l_options $srcdirfile $destdirfile echo "lalit test after" echo "**************************options below" echo "loption $l_options" echo "src $srcdirfile" echo "destinat... (3 Replies)
Discussion started by: lalitpct
3 Replies

6. HP-UX

Succesfully completion of a command in unix script

Hi, I want to wrote a script. say it has 4 command(e.g. a,b,c,d). I want my script to progress b if a completes succesfully. So can you please let me know what command/parameter i need to set. Thanks, Malay (2 Replies)
Discussion started by: malaya_17
2 Replies

7. Shell Programming and Scripting

How To Run Mml Command From Unix Script

Dear All I want to run some MML command on my node from my unix server. I am able to get mml prompt but after that my script is stop at mml prompt. No commnad is executed on mml prompt. Kindly help me out. Regards Jaydeep (0 Replies)
Discussion started by: jaydeep_sadaria
0 Replies

8. UNIX for Advanced & Expert Users

unix script for repeating a command with a variable

Hi need urgent help , for creating unix script . To collect system name,This is command i want to execute n (integer) no. of times for for a differnt IP addresses .IP is variable in every execution. Other string & collecter name is constant . snmpGet %IP% sysName.0 -c <string> -S <datacollecter... (2 Replies)
Discussion started by: langdatyagi
2 Replies

9. UNIX for Advanced & Expert Users

help required in unix command/script

Hi All, Please help me in writting the script File contains: ========= 11424444, <basicpage> jfalfksf <dateofbirth>10/02/2005</dateofbrith> jkaklgja lg'd .... 11423224444, <basicpage> jfalfksf <dateofbirth>11/02/2005</dateofbrith> jkaklgja lg'd 11433523224444, <basicpage>... (1 Reply)
Discussion started by: thaduka
1 Replies

10. UNIX for Advanced & Expert Users

Unix chroot + script command

Hi all, I have problems using the script command in a chroot enviroment. I have copied all the neccesary libraries into the jail and I have also created the ptys devices. When I tried to execute de command I get openpty failed Terminated Any suggestions? Thanks in Advance Ana (0 Replies)
Discussion started by: jannita
0 Replies
Login or Register to Ask a Question