Remove part of a file based on identifiers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove part of a file based on identifiers
# 1  
Old 02-19-2013
Remove part of a file based on identifiers

here below is a part of the file

Code:
cat fileName.txt
 
NAME=APP-VA-va_mediaservices-113009-VA_MS_MEDIA_SERVER_NOT_PRESENT-S
FIXED=false
DATE= 2013-02-19 03:46:04.4
PRIORITY=HIGH
RESOURCE NAME=ccm113
 
NAME=APP-DS-ds_ha-140020-databaseReplicationFailure-S
FIXED=false
DATE= 2013-02-19 03:46:04.4
PRIORITY=LOW
RESOURCE NAME=ccm113
 
NAME=APP-MS-service_monitoring-118035-MS_DeviceDeployError-S
FIXED=false
DATE= 2013-02-19 03:46:04.4
PRIORITY=HIGH
RESOURCE NAME=ccm113
 
NAME=APP-VA-va_trunkgroup_mgr-114000-VA_TGM_TRUNK_FAILURE-S
FIXED=false
DATE= 2013-02-17 07:58:55.3
PRIORITY=HIGH
RESOURCE NAME=ccm114


this file is divided into blocks.. starting from Name and ending with Resource Name.... so if any block whose priority is LOW, i need to remove that block from the file... so what my final output file should have is

Code:
cat fileName.txt
 
NAME=APP-VA-va_mediaservices-113009-VA_MS_MEDIA_SERVER_NOT_PRESENT-S
FIXED=false
DATE= 2013-02-19 03:46:04.4
PRIORITY=HIGH
RESOURCE NAME=ccm113
 
NAME=APP-MS-service_monitoring-118035-MS_DeviceDeployError-S
FIXED=false
DATE= 2013-02-19 03:46:04.4
PRIORITY=HIGH
RESOURCE NAME=ccm113
 
NAME=APP-VA-va_trunkgroup_mgr-114000-VA_TGM_TRUNK_FAILURE-S
FIXED=false
DATE= 2013-02-17 07:58:55.3
PRIORITY=HIGH
RESOURCE NAME=ccm114


any help is appreciated.. thanks
# 2  
Old 02-19-2013
Try

Code:
awk -F "=" '$1=="NAME"{for(i=1;i<=X;i++){if(!t){print A[i]}};X=t=0}
{A[++X]=$0}
$2=="LOW"{t++}
END{for(i=1;i<=X;i++){if(!t){print A[i]}}}' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 02-19-2013
If you are running on AIX, you can use the -p flag on grep to get a paragraph.
Code:
grep -pv "PRIORITY=LOW" infile > outfile


I'm not sure if this will help, as it depends on your OS, but it's neat if you have it available.



Robin
Liverpool/Blackburn,
UK
# 4  
Old 02-19-2013
This can easy be down with awk
Code:
awk '!/LOW/' RS="\n *\n" ORS="\n\n" infile

Since your input file does have one space I did add * space,star as RS
Code:
NAME=APP-VA-va_mediaservices-113009-VA_MS_MEDIA_SERVER_NOT_PRESENT-S
FIXED=false
DATE= 2013-02-19 03:46:04.4
PRIORITY=HIGH
RESOURCE NAME=ccm113

NAME=APP-MS-service_monitoring-118035-MS_DeviceDeployError-S
FIXED=false
DATE= 2013-02-19 03:46:04.4
PRIORITY=HIGH
RESOURCE NAME=ccm113

NAME=APP-VA-va_trunkgroup_mgr-114000-VA_TGM_TRUNK_FAILURE-S
FIXED=false
DATE= 2013-02-17 07:58:55.3
PRIORITY=HIGH
RESOURCE NAME=ccm114

This User Gave Thanks to Jotne For This Post:
# 5  
Old 02-21-2013
thanks a lot pamu.. it worked :-)

---------- Post updated at 03:36 PM ---------- Previous update was at 01:38 PM ----------

Thanks jotne .. your code worked fine too :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove part of the file using a condition

Gents, Is there the chance to remove part of the file, Taking in consideration this condition. For each record the first row start with the string % VE should be 56 rows for each records.. first row = % VE last row = % sw total 56 rows for each record. Then in the case that the... (4 Replies)
Discussion started by: jiam912
4 Replies

2. Shell Programming and Scripting

Discard part of a file based on a pattern ---

I have the file: s3_T0(2) Pos "1" "2" s1_T1(2) Pos "1" "2" --- 0 0 1 0 0 1 1 1 --- 1 2 "tau0" 1 2 "h10" I want to patternmatch on --- and get only the third part i.e. 1 2 "tau0" 1 2 "h10" I wanted to start simple but even something like (5 Replies)
Discussion started by: eagle_fly
5 Replies

3. Shell Programming and Scripting

How to remove the date part of the file?

Hi Gurus, I have file name like: abcd.20131005.dat I need to remove mid part of data final name should be abcd.dat thanks in advance (2 Replies)
Discussion started by: ken6503
2 Replies

4. Shell Programming and Scripting

Grep a part of file based on string identifiers

consider below file contents cat myOutputFIle.txt 8 CCM-HQE-ResourceHealthCheck: Resource List : No RED/UNKNOWN resource Health entries found ---------------------------------------------------------- 9 CCM-TraderLogin-Status: Number of logins: 0... (4 Replies)
Discussion started by: vivek d r
4 Replies

5. Shell Programming and Scripting

cut a line into different fields based on identifiers

cat fileanme.txt custom1=, custom2=, userPulseId=3005, accountPolicyId=1, custom3=, custom4=, homeLocationId=0, i need to make the fields appear in next line based on identifier (,) ie comma so output should read cat fileanme.txt custom1=, custom2=, userPulseId=3005, ... (8 Replies)
Discussion started by: vivek d r
8 Replies

6. Shell Programming and Scripting

Extracting lines based on identifiers into multiple files respectively

consider the following is the contents of the file cat 11.sql drop procedure if exists hoop1 ; Delimiter $$ CREATE PROCEDURE hoop1(id int) BEGIN END $$ Delimiter ; . . . . drop procedure if exists hoop2; Delimiter $$ CREATE PROCEDURE hoop2(id int) BEGIN END $$ (8 Replies)
Discussion started by: vivek d r
8 Replies

7. Shell Programming and Scripting

Extracting few lines from a file based on identifiers dynamically

i have something like this in a file called mysqldump.sql -- -- Table structure for table `Table11` -- DROP TABLE IF EXISTS `Table11`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Table11` ( `id` int(11) NOT NULL... (14 Replies)
Discussion started by: vivek d r
14 Replies

8. Shell Programming and Scripting

Remove part of the file

I have an xml file, from where I need to take out Application2 entries and keep the others. I need to remove from <product> to </product> and the key element to look for while removing should be <application> as other pairs can be same for others. <product> ... (10 Replies)
Discussion started by: chiru_h
10 Replies

9. Shell Programming and Scripting

remove certain part of file name

Hi, Is it possible to remove the first part of the file name using find. i.e i have something like 2006abc.txt , 1007bed.txt etc, I wanna rename them to abc.txt , bed.txt I tried some stupid way.. find . -name '*.txt' -exec mv {} `cut -f2-5 -d"_" {}` \; somehow iam not getting it. ... (3 Replies)
Discussion started by: braindrain
3 Replies

10. HP-UX

How do I take out(remove) the date part in the file name?

Hi Guys here I am again, I have two files in a specified location. Location ex: /opt/xdm/input/ input file names: 1. abc_app.yyyymmdd.dtd 2. abd_app.yyyymmdd.dtd I need to build a code that reads the files from the location based on the oldest date and cuts the date part... (5 Replies)
Discussion started by: ruthless
5 Replies
Login or Register to Ask a Question