Sponsored Content
Top Forums Shell Programming and Scripting search for keyword in subsequent lines and delete the second line Post 302346190 by rdhanek on Friday 21st of August 2009 08:09:45 AM
Old 08-21-2009
search for keyword in subsequent lines and delete the second line

I have my data something like this

I need to search for the keyword yyyy in the susequent lines and if it is present, delete the second line with keyword.

In other words, if a keywords is found in two subsequent lines delete the second line.

input data:
Code:
aaaa bbbbb cccc dddd
xxxx yyyy xxxxx abc
xxxx yyyy xxxxx xyz
aaaa bbbbb cccc dddd
rrrrrrrrr ttttttt yyyy
xxxx yyyy xxxx
aaaa bbbbb cccc dddd

Code:
output expected:
aaaa bbbbb cccc dddd
xxxx yyyy xxxxx abc
aaaa bbbbb cccc dddd
rrrrrrrrr ttttttt yyyy
xxxx yyyy xxxx
aaaa bbbbb cccc dddd

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search 2 lines and delete above line

Hi, I've been searching in this forum for the last 4 hours trying to do one thing: search 2 lines and delete the above line. So far I have not be able to find something similar in this forum, so I need help. This is what I'm trying to do. For example, I have a file called file1: file1 word1... (4 Replies)
Discussion started by: shamushamu
4 Replies

2. Shell Programming and Scripting

replace only 1st word of a line if it comes in the subsequent lines at same postion.

I have a file like this.. Maharastra Mumbai worli Maharastra Mumbai navy maharatra Pune Maharastra Nagpur Karnataka Bangalore Karnataka Mysore Karnataka Mangalore Punjab Amritsar punjab Jalandar my expected outcome should be like this Maharastra Mumbai worli ---------- ... (9 Replies)
Discussion started by: geeko
9 Replies

3. Shell Programming and Scripting

Delete the lines after the last instance of the keyword

I have my input sometyhing like this aaa bbbbbb cccccc ddddd eeeee 1234 ravi kumar aaaaaa vvvvvvv 5678 ravi kumar rrrrrrr mmmmmmm I want the output as follows. aaa bbbbbb cccccc ddddd eeeee 1234 ravi kumar aaaaaa vvvvvvv 5678 ravi kumar (2 Replies)
Discussion started by: rdhanek
2 Replies

4. Shell Programming and Scripting

Delete the lines before the first instance of the keyword

I have my data something like this. I want to delete all the lines before the frist instance of the key word 'ravi kumar' aaa bbbbbb cccccc ddddd eeeee 1234 ravi kumar aaaaaa vvvvvvv 5678 ravi kumar rrrrrrr mmmmmmm I want the output as follows. 1234 ravi kumar aaaaaa... (8 Replies)
Discussion started by: rdhanek
8 Replies

5. Shell Programming and Scripting

How to search for keywords in subsequent lines

Hi all, I am looking for a coomand to search for the keywords in susequenct lines. Keyword1 in a line and Keyword2 in the very next line. Once i found the combination ineed to print the lines with patterns and the line above and one below. I am giving an example here: Keywords are :ERROR and... (12 Replies)
Discussion started by: rdhanek
12 Replies

6. Shell Programming and Scripting

Using sed to delete a line having a particular keyword

Hi Geeks :b:, I need to delete a line from file that contains a particular keyword. I had read in some forum of unix.com that below code could be used sed "/$titlesearch/d" movielist >tmp mv tmp movielist But my file contains lines which contain slashes (/) FOr eg: /etc/movie/title/... (5 Replies)
Discussion started by: ajincoep
5 Replies

7. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

8. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

9. UNIX for Advanced & Expert Users

Need command for grepping pattern lines with subsequent lines

Hi, I have a requirement like, I have a list of pattens in a file say pattern.txt, PHC111 PHC113 and in another file called master.lst i have entries like, PHC111 a b PHC112 a PHC113 b c PHC114 d e (5 Replies)
Discussion started by: rbalaj16
5 Replies

10. Shell Programming and Scripting

Search for a Keyword in file and replace another keyword or add at the end of line

Hi I want to implement something like this: if( keyword1 exists) then check if(keyword2 exists in the same line) then replace keyword 2 with New_Keyword else Add New_Keyword at the end of line end if eg: Check for Keyword JUNGLE and add/replace... (7 Replies)
Discussion started by: dashing201
7 Replies
hierarch28(1)						      General Commands Manual						     hierarch28(1)

NAME
hierarch28 - header conversion from ESO to standard FITS SYNOPSIS
hierarch28 [options] <FITS> [table] DESCRIPTION
hierarch28 will convert keyword names in a FITS header to new names, using a user-provided ASCII conversion table. It is especially aimed at removing no-standard FITS features, such as the HIERARCH ESO keyword names. hierarch28 can also perform a translation to the IRAF convention on the following four keywords: 'RA', 'DEC', 'UT' and 'LST'. IRAF requires these keywords to contain the string representation of their values, e.g. RA = ' 09:45:14.594' DEC = '-33:47:09.420' UT = ' 01:17:21.950' LST = ' 08:19:59.688' The ESO standard (see http://archive.eso.org/dicb) defines these keywords as floating point values with the units degrees for RA/DEC and elapsed seconds since midnight for UT/LST. In order to have this translation performed, add RA = RA DEC = DEC UT = UT LST = LST to the conversion table. OPTIONS
-g This option is used to generate default translation tables. FILES
hierarch28 expects a conversion table in input. Default name for this table is table.conv in the current working directory. Indicate another name for this file as last argument on the command-line. This ASCII file contains a list of keywords to replace, in the following format: # # Comment lines start with a hash '#' # Blank lines would be ignored # OLDKEYWORD1 = NEWKEYWORD1 OLDKEYWORD2 = NEWKEYWORD2 etc. Input keywords are character strings, they may contain blanks. Example: HIERARCH ESO DET DIT = DETDIT One important restriction is that the new keyword name may not be longer than the initial one. The program will complain that it cannot achieve search and replace if this is the case. IMPORTANT
This programs achieves maximal speed to operate because it modifies the input file directly. Be aware that using hierarch28 on a file will modify its contents in an irreversible way! 29 May 2000 hierarch28(1)
All times are GMT -4. The time now is 12:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy