Sponsored Content
Top Forums Shell Programming and Scripting searching and storing unknown number of lines based on the string with a condition Post 302191062 by chappidi_pradee on Thursday 1st of May 2008 11:32:40 AM
Old 05-01-2008
hello please try this.

hope this helps you out :-)

please runthis from a script.

awk ' /^= name*/,/^= job*/ { indx += 1; arr[indx]=$0; } \
/^= code : 10/ { match_found_10="YES"; } \
/^= code : 15/ { match_found_15="YES"; }\
/^= job*/ {if(match_found_10=="YES") { \
print "======================" >"code_10_match_file"; \
for(i=1; i<=indx; i++) \
print arr[i] >"code_10_match_file"; \
print "======================" >"code_10_match_file";\
}\
if(match_found_15=="YES") { \
print "======================" >"code_15_match_file"; \
for(i=1; i<=indx; i++) \
print arr[i] >"code_15_match_file"; \
print "======================" >"code_15_match_file";\
}\
match_found_10="NO"; indx = 0; match_found_15="NO"; }\
' input_file_name
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to split the String based on condition?

hi , I have a String str="/opt/ibm/lotus/ibw/latest" or ="/opt/lotus/ibw/latest" this value is dynamic..I want to split this string into 2 strings 1. /opt/ibm/lotus(/opt/lotus) this string must ends with "lotus" 2./ibw/latest can any body help me on this? Regards, sankar (2 Replies)
Discussion started by: sankar reddy
2 Replies

2. Shell Programming and Scripting

sed - searching for string and storing in variable

Hi I'm trying to find a way to search a text file for a specific string. I have a file which contains i.p. addresses and port numbers in the following format: 'ip="www.xxx.yyy.zzz"' 'port="xx""' I want to print only the parts between the double quotes for use in seperate variables,... (4 Replies)
Discussion started by: melias
4 Replies

3. Shell Programming and Scripting

awk to print lines based on string match on another line and condition

Hi folks, I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and... (5 Replies)
Discussion started by: rowie718
5 Replies

4. Shell Programming and Scripting

Remove lines from XML based on condition

Hi, I need to remove some lines from an XML file is the value within a tag is empty. Imagine this scenario, <acd><acdID>2</acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> I... (3 Replies)
Discussion started by: giles.cardew
3 Replies

5. Shell Programming and Scripting

Merge two non-consecutive lines based on line number or string

This is a variation of an earlier post found here: unixcom/shell-programming-scripting/159821-merge-two-non-consecutive-lines.html User Bartus11 was kind enough to solve that example. Previously, I needed help combining two lines that are non-consecutive in a file. Now I need to do the... (7 Replies)
Discussion started by: munkee
7 Replies

6. Shell Programming and Scripting

Arithmetic (number-based) if condition

Hi Folks I'm looking for help with if statement. I'm reading the file with header (starts with 0 on position 1 in the line) and data (starts with 1 on position 1 in the line). I have to check if the number from header (should be number of data rows) equal actual count of the data rows. ... (4 Replies)
Discussion started by: viallos
4 Replies

7. Shell Programming and Scripting

Print certain lines based on condition

Hi All, I have following listing Filesystem GB blocks Free Used Iused Iused Mounted on /dev/hd2 4.00 0.31 93 63080 43 /usr Filesystem GB blocks Free Used Iused Iused Mounted on Filesystem GB blocks Free Used Iused Iused... (11 Replies)
Discussion started by: ckwan
11 Replies

8. Shell Programming and Scripting

Delete lines from file based on condition

I want to keep last 2 days data from a file and want to delete others data from the file. Please help me. Sample Input # cat messages-2 Apr 15 11:25:03 test1 kernel: imklog 4.6.2, log source = /proc/kmsg started. Apr 15 11:25:03 test1 rsyslogd: (re)start Apr 16 19:42:03 test1 kernel:... (2 Replies)
Discussion started by: makauser
2 Replies

9. Shell Programming and Scripting

Print lines based on line number and specified condition

Hi, I have a file like below. 1,2,3,4,5,6,7,8,9I would like to print or copied to a file based of line count in perl If I gave a condition 1 to 3 then it should iterate over above file and print 1 to 3 and then again 1 to 3 etc. output should be 1,2,3 4,5,6 7,8,9 (10 Replies)
Discussion started by: Anjan1
10 Replies

10. Shell Programming and Scripting

awk to reformat lines based on condition

The awk below uses the tab-delimeted fileand reformats each line based on one of three conditions (rules). The 3 rules are for deletion (lines in blue), snv (line in red), and insertion (lines in green). I have included all possible combinations of lines from my actual data, which is very large.... (0 Replies)
Discussion started by: cmccabe
0 Replies
PROP_ARRAY_UTIL(3)					   BSD Library Functions Manual 					PROP_ARRAY_UTIL(3)

NAME
prop_array_util, prop_array_get_bool, prop_array_set_bool, prop_array_get_int8, prop_array_get_uint8, prop_array_set_int8, prop_array_set_uint8, prop_array_get_int16, prop_array_get_uint16, prop_array_set_int16, prop_array_set_uint16, prop_array_get_int32, prop_array_get_uint32, prop_array_set_int32, prop_array_set_uint32, prop_array_get_int64, prop_array_get_uint64, prop_array_set_int64, prop_array_set_uint64, prop_array_add_int8, prop_array_add_uint8, prop_array_add_int16, prop_array_add_uint16, prop_array_add_int32, prop_array_add_uint32, prop_array_add_int64, prop_array_add_uint64, prop_array_get_cstring, prop_array_set_cstring, prop_array_get_cstring_nocopy, prop_array_set_cstring_nocopy, prop_array_add_and_rel -- array property collection object utility functions LIBRARY
Property Container Object Library (libprop, -lprop) SYNOPSIS
#include <prop/proplib.h> bool prop_array_get_bool(prop_array_t dict, unsigned int indx, bool *valp); bool prop_array_set_bool(prop_array_t dict, unsigned int indx, bool val); bool prop_array_get_int8(prop_array_t dict, unsigned int indx, int8_t *valp); bool prop_array_get_uint8(prop_array_t dict, unsigned int indx, uint8_t *valp); bool prop_array_set_int8(prop_array_t dict, unsigned int indx, int8_t val); bool prop_array_set_uint8(prop_array_t dict, unsigned int indx, uint8_t val); bool prop_array_get_int16(prop_array_t dict, unsigned int indx, int16_t *valp); bool prop_array_get_uint16(prop_array_t dict, unsigned int indx, uint16_t *valp); bool prop_array_set_int16(prop_array_t dict, unsigned int indx, int16_t val); bool prop_array_set_uint16(prop_array_t dict, unsigned int indx, uint16_t val); bool prop_array_get_int32(prop_array_t dict, unsigned int indx, int32_t *valp); bool prop_array_get_uint32(prop_array_t dict, unsigned int indx, uint32_t *valp); bool prop_array_set_int32(prop_array_t dict, unsigned int indx, int32_t val); bool prop_array_set_uint32(prop_array_t dict, unsigned int indx, uint32_t val); bool prop_array_get_int64(prop_array_t dict, unsigned int indx, int64_t *valp); bool prop_array_get_uint64(prop_array_t dict, unsigned int indx, uint64_t *valp); bool prop_array_set_int64(prop_array_t dict, unsigned int indx, int64_t val); bool prop_array_set_uint64(prop_array_t dict, unsigned int indx, uint64_t val); bool prop_array_set_int32(prop_array_t dict, unsigned int indx, int32_t val); bool prop_array_set_uint32(prop_array_t dict, unsigned int indx, uint32_t val); bool prop_array_add_int8(prop_array_t dict, int8_t val); bool prop_array_add_uint8(prop_array_t dict, uint8_t val); bool prop_array_add_int16(prop_array_t dict, int16_t val); bool prop_array_add_uint16(prop_array_t dict, uint16_t val); bool prop_array_add_int32(prop_array_t dict, int32_t val); bool prop_array_add_uint32(prop_array_t dict, uint32_t val); bool prop_array_add_int64(prop_array_t dict, int64_t val); bool prop_array_add_uint64(prop_array_t dict, uint64_t val); bool prop_array_get_cstring(prop_array_t dict, unsigned int indx, char **strp); bool prop_array_set_cstring(prop_array_t dict, unsigned int indx, const char *str); bool prop_array_get_cstring_nocopy(prop_array_t dict, unsigned int indx, const char **strp); bool prop_array_set_cstring_nocopy(prop_array_t dict, unsigned int indx, const char *strp); bool prop_array_add_and_rel(prop_array_t dict, prop_object_t obj); DESCRIPTION
The prop_array_util family of functions are provided to make getting and setting values in arrays more convenient in some applications. The getters check the type of the returned object and, in some cases, also ensure that the returned value is within the range implied by the getter's value type. The setters handle object creation and release for the caller. The prop_array_get_cstring() function returns dynamically allocated memory. See prop_string(3) for more information. The prop_array_get_cstring_nocopy() and prop_array_set_cstring_nocopy() functions do not copy the string that is set or returned. See prop_string(3) for more information. The prop_array_add_and_rel() function adds the object to the end of the array and releases it. The object is also released on failure. RETURN VALUES
The prop_array_util getter functions return true if the object exists in the array and the value is in-range, or false otherwise. The prop_array_util setter functions return true if creating the object and storing it in the array is successful, or false otherwise. SEE ALSO
prop_array(3), prop_bool(3), prop_number(3), proplib(3) HISTORY
The proplib property container object library first appeared in NetBSD 4.0. BSD
March 12, 2011 BSD
All times are GMT -4. The time now is 07:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy