UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 13th, 2006, 06:57 AM
AbuShreek AbuShreek is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 1 AbuShreek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 47 sec
Reputation Power: 0
UNIX Script Help

Hello,

I am new to UNIX shell scripting but I am willing to learn :-)…

I have to use the C shell....

I have to write a script that should do the following:
- Open an input file and read it line by line.
- For each line read, I have to search for a certain pattern. If it was found then I have to ignore the following two lines and read the following line and store it for further processing. Otherwise, I will just read the following line.
- After the previously mentioned hit is found and the following desired line is read, I have to write one line to another output file that is composed of some texts from the previously read files.
- I have to do that till the end of the file.
- I have to automate the process (this is not important and can be delayed).

Please help me.

Thanks in advance.

Example of the input file:

LOADING PROGRAM VERSION 5.1-0

Cont BXX1 2006-06-03 14:49:54

ALARM HISTORY

<HIST> BXX1 MCMU-0 TRANSM 2006-06-03 10:26:56.75
** ALARM ........ RRM_BX
(0330) INCORRECT STATUS
81d 2d 00 96d 11d 0d

<HIST> BXX1 MCMU-0 TRANSM 2006-06-03 10:28:40.73
.. CANCEL ........ RRM_BX
(0330) INCORRECT STATUS
81d 2d 00 96d 11d 0d

Example of the output file:
exemmlm -n BXX1 -c "EX:CMDx=81,CMDy=2,CMDz=00:L;"
exemmlm -n BXX1 -c "EX:CMDx=81,CMDy=2,CMDz=00:L;"

Reply With Quote
  #2  
Old June 13th, 2006, 09:25 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Novice (500 - 999 posts) Click here for more information
 
Join Date: Mar 2006
Posts: 772 SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 1 h 37 m 46 sec
Reputation Power: 327
Yuk! It may not sound obvious but you may want to take a look at awk.
With that you can process a file, setting up a pattern match which, when found will read next 2 lines (and ignore them!), plus you should be able to save previous information in variables to help with the output.
Looking at things, it appears your string being looked for is BXX1, so something like:
awk '/<HIST> BXX1/ {getline; getline; x=$1; y=$2; z=$3; printf("exemmlm -n BXX1 -c \"EX:CMDx=%s,CMDy=%s,CMDz=%s:L;\"\n",x,y,z)}'
That is just off the top of myhead and you would need to arrange for the alphas to be dropped from the end of the "81d" field to leave you with just 81. Also, you'd need to redirect output to your file.
The awk man pages should help you out with that.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > UNIX Script Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT