Need Help !!! simple query


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help !!! simple query
# 1  
Old 07-29-2008
Need Help !!! simple query

Dear,

I have a alarm text file, containing minor and major alarms, i am intrested in Mojor alarm with its alarm header and next four lines in seperate file....

Can anybody help me with this below is the alarm file output.

:SEV="MAJOR":
Object-Instance %
unit-type % bts nbr % 25
SBL-type % tre nbr % 4 subnb % 255


:SEV="MINOR":
Object-Instance %
unit-type % bts nbr % 8
SBL-type % ra nbr % 2 subnb % 255

:SEV="MAJOR":
Object-Instance %
unit-type % bts nbr % 24
SBL-type % tre nbr % 4 subnb % 255
# 2  
Old 07-29-2008
Code:
awk>outfile '/MAJOR/' ORS="\n\n" RS= infile

Code:
perl>outfile -00 -nle'print if /MAJOR/' infile

Code:
ruby>outfile -00 -nle'print if /MAJOR/' infile

# 3  
Old 07-29-2008
NEED Help !!! Simple Query

Dear radoulov,

Thanks a lot for the quick reply.


Can you please tell me what is representing first and second "n" below with ORS.
Thanks a lot

awk>outfile '/MAJOR/' ORS="\n\n" RS= infile
# 4  
Old 07-29-2008
The \n sequence represents a new line. You need to set the Output Record Seperator to two new lines because the default is one and the output will be like this:

Code:
:SEV="MAJOR":
Object-Instance %
unit-type % bts nbr % 25
SBL-type % tre nbr % 4 subnb % 255
:SEV="MAJOR":
Object-Instance %
unit-type % bts nbr % 24
SBL-type % tre nbr % 4 subnb % 255

# 5  
Old 07-29-2008
Quote:
Originally Posted by Danish Shakil
:SEV="MAJOR":
Object-Instance %
unit-type % bts nbr % 25
SBL-type % tre nbr % 4 subnb % 255
How about just:

Code:
grep -A 3 'MAJOR'

Or, if you want to be sure you get exactly what you ask for:
Code:
grep -A 3 -E '^:SEV="MAJOR":$'

# 6  
Old 07-29-2008
First the A B switches are available only in GNU grep,
second, the above solution handles only a fixed length paragraphs.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Oracle simple SQL query result in: ORA-08103: object no longer exists

Dear community, please help with a query on Oracle. I'm using SQLPlus (but with SQLDeveloper is the same) to accamplish a sinple query like: select count(*) from ARCHIT_D_TB where (TYP_ID=22 OR TYP_ID=23) and SUB_TM like '%SEP%' and CONS=1234This is a very simple query that works perfect until... (5 Replies)
Discussion started by: Lord Spectre
5 Replies

2. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

5. Programming

A simple C program query ...

Given the following code inside the function ext3_write_super(): (It's there in Linux kernel 2.6.27.59) static void ext3_write_super (struct super_block * sb) { if (mutex_trylock(&sb->s_lock) != 0) BUG(); sb->s_dirt = 0; } The conditional test at if... (2 Replies)
Discussion started by: Praveen_218
2 Replies

6. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

7. Shell Programming and Scripting

add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable? $result = odbc_exec($connect, $query); while ($row = odbc_fetch_array($result)) { echo $row,"\n"; } odbc_close($connect); ?> This will output hostnames: host1... (0 Replies)
Discussion started by: hazno
0 Replies

8. Shell Programming and Scripting

A simple query on unix shell script

I want to write a script to go to particular path in file and run shell script from there. what will be shell script for the same. (2 Replies)
Discussion started by: shekhar_ssm
2 Replies

9. UNIX for Dummies Questions & Answers

Simple loop query

Hi All Just started with shell scripts and am stumped by, what is to most of you no doubt, a simple issue. All I'm trying to do is prompt a user for input and writing to a log file. If the user types the word 'stop', then the program should halt. If the word typed is 'clear', then the log file... (2 Replies)
Discussion started by: kutz13
2 Replies

10. UNIX for Dummies Questions & Answers

simple sed query

hi, i would like to replace a string in a series of files with another string, without outputting to new files. is this possible? i've tried using sed, and started by trying to alter the contents of one file... sed 's/string1/string2/g' file.txt but while this does the replacement on... (2 Replies)
Discussion started by: schmark
2 Replies
Login or Register to Ask a Question