After eliminating then save as a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting After eliminating then save as a string
# 1  
Old 02-16-2010
After eliminating then save as a string

Hello,
I am using HP-UX B.11.23 U ia64 2591592275 unlimited-user license
I am trying to write a sh script on my own system to pass string of word as one parameter


The format of the string will be the same
But the content after : will be changed each time

If you manage to have this as $*

The content of these string are
Code:
[1] private.enterprises.gsi.notification.notifyTrap.ntDispatchId (OctetString): 1014280
[2] private.enterprises.gsi.notification.notifyTrap.ntHostId (OctetString): uattd01
[3] private.enterprises.gsi.notification.notifyTrap.ntMemberName (OctetString): enguard
[4] private.enterprises.gsi.notification.notifyTrap.ntAlertGroup (OctetString): es_ops
[5] private.enterprises.gsi.notification.notifyTrap.ntAlertId (OctetString): 1001
[6] private.enterprises.gsi.notification.notifyTrap.ntAlertSeverity (OctetString): CRITICAL
[7] private.enterprises.gsi.notification.notifyTrap.ntAlertType (OctetString): Log
[8] private.enterprises.gsi.notification.notifyTrap.ntAlertDesc (OctetString): SAF_RTFATM count for SAF_RTFATM
[9] private.enterprises.gsi.notification.notifyTrap.ntAlertText (OctetString): SAF FILE SAF_RTFATM detected a count of 77 records.
[10] private.enterprises.gsi.notification.notifyTrap.ntHostDate (OctetString): 02/16/2010
[11] private.enterprises.gsi.notification.notifyTrap.ntHostTime (OctetString): 14:56
[12] private.enterprises.gsi.notification.notifyTrap.ntCreateDate (OctetString): 02/16/10
[13] private.enterprises.gsi.notification.notifyTrap.ntCreateTime (OctetString): 11:24
[14] private.enterprises.gsi.notification.notifyTrap.14 (OctetString): SAFCHCK
[15] private.enterprises.gsi.notification.notifyTrap.15 (OctetString):
[16] private.enterprises.hp.nm.openView.openViewTrapVars.openViewSourceName.0 (OctetString): 10.0.2.23

I need to have each one after :
after eliminating the header
so fo this one
Code:
[1] private.enterprises.gsi.notification.notifyTrap.ntDispatchId (OctetString): 1014280

so for this one we need it to become
Code:
String1=1014280

so we eliminate [1] private.enterprises.gsi.notification.notifyTrap.ntDispatchId (OctetString):

same thing with
Code:
[2] private.enterprises.gsi.notification.notifyTrap.ntHostId (OctetString): uattd01
String2= uattd01 etc

Thanks in advance
Smilie

Last edited by Scott; 02-16-2010 at 09:51 AM.. Reason: Removed formatting, added code tags
# 2  
Old 02-16-2010
If i get you correctly...

Code:
awk -F: '{$1="string"++i;print $1"="$2}' infile

# 3  
Old 02-16-2010
hello Malcomex

thanks for your reply

i am not used to script

can explain more ...


let me clerfiy one thing here

i need anything after
Code:
[1] private.enterprises.gsi.notification.notifyTrap.ntDispatchId (OctetString):

and before
Code:
[2] private.enterprises.gsi.notification.notifyTrap.ntHostId (OctetString):

as string1


same thing with string2
anything after
Code:
[2] private.enterprises.gsi.notification.notifyTrap.ntHostId (OctetString):

and before
Code:
[3] private.enterprises.gsi.notification.notifyTrap.ntMemberName (OctetString):


thanks

Last edited by Scott; 02-16-2010 at 09:53 AM.. Reason: Removed formatting, added code tags
# 4  
Old 02-16-2010
i guess what i posted above will give you what you want.

You might need to read this to know about it...
Awk - A Tutorial and Introduction - by Bruce Barnett
# 5  
Old 02-20-2010
thanks malcome

but i did not get it.


what i want to separate these as comma or special character

i want it like this

save anything after this
Code:
[1] private.enterprises.gsi.notification.notifyTrap.ntDispatchId (OctetString):



and before
Code:
[2] private.enterprises.gsi.notification.notifyTrap.ntHostId (OctetString):



as string 1 and so on

how to define this as separation ( in example 10x)


thanks
# 6  
Old 02-20-2010
can you show how exactly your desired output should look like?
And what do you mean by save, do you mean you want to save it in variable? Can you elaborate a little bit and show your desired output?
# 7  
Old 02-20-2010
thanks for your reply
\please note that the before (OctetString): are fix format they will never change
the one after (OctetString): will alawys be changed


Code:
 
[1] private.enterprises.gsi.notification.notifyTrap.ntDispatchId (OctetString): 1014280
[2] private.enterprises.gsi.notification.notifyTrap.ntHostId (OctetString): uattd01
[3] private.enterprises.gsi.notification.notifyTrap.ntMemberName (OctetString): enguard
[4] private.enterprises.gsi.notification.notifyTrap.ntAlertGroup (OctetString): es_ops
[5] private.enterprises.gsi.notification.notifyTrap.ntAlertId (OctetString): 1001
[6] private.enterprises.gsi.notification.notifyTrap.ntAlertSeverity (OctetString): CRITICAL
[7] private.enterprises.gsi.notification.notifyTrap.ntAlertType (OctetString): Log
[8] private.enterprises.gsi.notification.notifyTrap.ntAlertDesc (OctetString): SAF_RTFATM count for SAF_RTFATM
[9] private.enterprises.gsi.notification.notifyTrap.ntAlertText (OctetString): SAF FILE SAF_RTFATM detected a count of 77 records.
[10] private.enterprises.gsi.notification.notifyTrap.ntHostDate (OctetString): 02/16/2010
[11] private.enterprises.gsi.notification.notifyTrap.ntHostTime (OctetString): 14:56
[12] private.enterprises.gsi.notification.notifyTrap.ntCreateDate (OctetString): 02/16/10
[13] private.enterprises.gsi.notification.notifyTrap.ntCreateTime (OctetString): 11:24
[14] private.enterprises.gsi.notification.notifyTrap.14 (OctetString): SAFCHCK
[15] private.enterprises.gsi.notification.notifyTrap.15 (OctetString):
[16] private.enterprises.hp.nm.openView.openViewTrapVars.openViewSourceName.0 (OctetString): 10.0.2.23





i need to save the words tha come after


Code:
[1] private.enterprises.gsi.notification.notifyTrap.ntDispatchId (OctetString):



and before


Code:
[2] private.enterprises.gsi.notification.notifyTrap.ntHostId (OctetString):

as st1 ( st1 variable i need to show it later and use it in case statement.


so in the output and in our case st1=1014280

and the same thing for st2
it will be anything come after
Code:
 
[2] private.enterprises.gsi.notification.notifyTrap.ntHostId (OctetString):

and before
Code:
 
[3] private.enterprises.gsi.notification.notifyTrap.ntMemberName (OctetString):

so at the output the variable st2=uattd01


same thing with st3 st4 st5 st6 st7 st8 st9 st10 till st16
note this string may have space like in st8

output of st8=SAF_RTFATM count for SAF_RTFATM

i hope it is clear right now ...


thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a particular string from column eliminating characters at the end.

Hi, So basically I have this file containing query output in seperated columns. In particular column I have the below strings: news news-prio I am trying to grep the string news without listing news-prio aswell. I tried grep "$MSG_TYPE" , grep -w "$MSG_TYPE" , grep... (4 Replies)
Discussion started by: nms
4 Replies

2. Shell Programming and Scripting

Save value from output of Corestat and save in a list for each core

I am trying to modify the "corestat v1.1" code which is in Perl.The typical output of this code is below: Core Utilization CoreId %Usr %Sys %Total ------ ----- ----- ------ 5 4.91 0.01 4.92 6 0.06 ... (0 Replies)
Discussion started by: Zam_1234
0 Replies

3. Shell Programming and Scripting

First zero is eliminating in the awk command

I am using something like this in my code nawk 'BEGIN{OFS=FS="|"} {$15='$CalaMig'} {print}' filename actually value of $CalaMig=01234 But its replacing as 1234 in the 15th postion.Its not taking the first zero. can some one help here (1 Reply)
Discussion started by: saj
1 Replies

4. UNIX for Dummies Questions & Answers

Replace a string within 2 points and save it

I've got this xml file <file1> some text here </file1> <file2> some text here </file2> How do I change the text in element file1 to a sentence that I want, defined by variable $sentence. using ksh here. (2 Replies)
Discussion started by: alienated
2 Replies

5. Shell Programming and Scripting

Save cURL verbose output to file or do it like browser "save as.."

hi there ! i have exactly the same problem like this guy here https://www.unix.com/shell-programming-scripting/127668-getting-curl-output-verbose-file.html i am not able to save the curl verbose output.. the sollution in this thread (redirecting stderr to a file) does not work for me.... (0 Replies)
Discussion started by: crabmeat
0 Replies

6. Shell Programming and Scripting

Eliminating output?

Hi Folks, I am writting a shell script for general purpose use.... i have created a function like below:- largest_file() { clear tput cup 20 30 echo please enter the full directory path where you want to search:- tput cup 21 30 read lr_choice1 tput cup 22 30 echo please... (3 Replies)
Discussion started by: rpraharaj84
3 Replies

7. Shell Programming and Scripting

search a string in a line and save it in a variable

Hi I want to read a file line by line and search for a particular string in each line(say for example string containing @ )and save that string into a variable. Can someone suggest me the way to implement it.I am using K- shell Thanks Ishita (5 Replies)
Discussion started by: Ishita
5 Replies

8. Shell Programming and Scripting

save every line in log file with matched string

i have been doing this script to match every line in a current log file (access_log) with strings that i list from a path (consist of 100 of user's name ex: meggae ).. and then make a directory of every string from the text file (/path/meggae/) --->if it matched.. then print every line from the... (3 Replies)
Discussion started by: meggae
3 Replies

9. UNIX for Dummies Questions & Answers

Eliminating CR (new lines) from a file.

Hi all, I made a C++ program in dos (in dev-C++) and uploaded it on Solaris box. On opening that file with 'vim' editor i found that there is some extra new lines after each written code line. I tried to find out is the file is in dos or in unix format, with 'file' command,and i got "<file-name>.h:... (4 Replies)
Discussion started by: KornFire
4 Replies

10. Shell Programming and Scripting

replace character in a string pattern and save the change in same file

I am facing one problem, can any one please suggest me the command for the same in unix. I am using Ksh. I have a large file with the data that looks like below. "ROTO2-2007f","_US01","9/15/2007","9/21/2007",346492,"NICK, LCD WATCH"97,1,"NAPOLITJ ","BERGER,M Z & CO INC",0.01, ... (2 Replies)
Discussion started by: mihir0011
2 Replies
Login or Register to Ask a Question