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?
# 1  
Old 09-02-2015
How to script / command this in UNIX?

Hello Guys,

From a given file I have to find out what are all values for "Application States :" and how many of them have same state.

eg :

If there are possible states in file :

Code:
Application States : Normal
Application States : Terminated
Application States : Pending

and if there are 10 Normal, 2 Terminated and 15 Pending applications then I want to have some script or unix grep command to show something like this :

Code:
Application States : Normal         : total = 10
Application States : Terminated   : total = 02
Application States : Pending        : total = 15

What would be the exact unix command or script to achieve above?
Moderator's Comments:
Mod Comment Please use CODE tags for sample input, sample output, and code segments; as required by forum rules.

Last edited by Don Cragun; 09-03-2015 at 12:00 AM.. Reason: Add CODE tags.
# 2  
Old 09-03-2015
What have you tried to solve this problem on your own?

Are we to assume by your login name that you are using an AIX system?
# 3  
Old 09-03-2015
I use below approach but its time consuming and not efficient Smilie
So i want to know how to do it in one command :

Code:
grep "Application States :" filename | sort | uniq

then depending on states I grep as below for each state

Code:
grep "Application States : Normal" filename | wc -l

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules instead of depending on forum moderators to clean up your posts.

Last edited by Don Cragun; 09-03-2015 at 01:17 AM.. Reason: Add CODE tags.
# 4  
Old 09-03-2015
Try and see if that works for you. If it does not work, please, post why and how it fails.
Code:
awk -F' : ' '
$1 == "Application States" {app[$2]++}
END {for(a in app){printf "Application States : %s : total = %02d\n", a, app[a]}
}' aixusrsys.file


Last edited by Aia; 09-03-2015 at 01:06 AM..
# 5  
Old 09-03-2015
Quote:
Originally Posted by Aia
Try and see if that works for you. If it does not work, please, post why and how it fails.
Code:
awk -F' : ' '
$1 == "Application States" {app[$2]++}
END {for(a in app){printf "Application States : %s : total = %02d\n", a, app[a]}
}' aixusrsys.file

Thanks, but it didn't returned anything and I confirmed the input file has multiple "Application States". Please let me know is any other way.
# 6  
Old 09-03-2015
You didn't provide any actual sample input, you didn't answer my question about what operating system you're using, and the application "states" you've shown us look more like possible values for "application status" than "application state". So, if Aia's suggestion doesn't work, you might also try:
Code:
awk '
/^Application Sta/ {
	c[$0]++
	if(length($0) > m)
		m = length($0)
}
END {	for(i in c)
		printf("%-*s   : total = %02d\n", m, i, c[i])
}' file

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
# 7  
Old 09-03-2015
Quote:
Originally Posted by aixusrsys
Thanks, but it didn't returned anything and I confirmed the input file has multiple "Application States". Please let me know is any other way.
Is it possible to post a few copy and paste lines from the original file?
Either the white spacing or the "Application States" string is not accurate in your example.
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