Sponsored Content
Top Forums Shell Programming and Scripting Remove every line with specific string, and also the one above and below it Post 302902682 by phpchick on Wednesday 21st of May 2014 05:14:48 PM
Old 05-21-2014
Remove every line with specific string, and also the one above and below it

I would like to identify every line with a specific string, in this case: "Mamma".
I would like to remove that line, and also the line above it and below it. So the below

Code:
Where are all amazing Flats
Look At The Great Big White
Hey There Hot Mamma
You Are So hot Baby
I wish You were Mine
Hee How Yee Haw
Hey There Hot Mamma
Wait A minute
Hee Haw Yee Haw
Hey There Hot Mamma
A song Is Here
Make me a List

Becomes

Code:
Where are all amazing Flats
I wish You were Mine
Make me a List


I was wondering if anyone could help me out? I've googled but it is a little complex for Google

---------- Post updated at 05:14 PM ---------- Previous update was at 05:07 PM ----------

I think this might work

sed -n '/Mamma/{N;s/.*//;x;d;};x;p;${x;p;}' file | sed '/^$/d'

Last edited by jim mcnamara; 05-21-2014 at 06:10 PM.. Reason: code tags
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove Line that contains specific string

I am looking for a way to remove any line in a text file that contains the string "Mac address". I guess you would grep and sed, but I am not sure how to do this. Thanks for you help. (3 Replies)
Discussion started by: CBarraford
3 Replies

2. UNIX for Dummies Questions & Answers

How to remove columns with specific string?

If I have a data test.txt with 1000 columns such as: id sex gene1 gene2 gene2.dl gene3 gene4 gene4.dl ....... 1 1 AA AT AT TT AT AT ....... 2 1 AG TT TT TA AA AA ....... 3 2 AA AT AT TT AT ... (2 Replies)
Discussion started by: AMBER
2 Replies

3. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

4. Shell Programming and Scripting

remove a specific line in a LARGE file

Hi guys, i have a really big file, and i want to remove a specific line. sed -i '5d' fileThis doesn't really work, it takes a lot of time... The whole script is supposed to remove every word containing less than 5 characters and currently looks like this: #!/bin/bash line="1"... (2 Replies)
Discussion started by: blubbiblubbkekz
2 Replies

5. Shell Programming and Scripting

Remove a specific line from grep output string

Dear All I want to search string "1000" from input file and if it found i want remove line that contain 1000 and also remove 3 line above it and 2 line below it. INPUT FILE: BHAT-D 2 aaa ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES 50 ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

6. UNIX for Dummies Questions & Answers

How to remove a string from a specific column in a file

Hello, A basic query. How can I remove a string from a specific column. For example, remove "abcd" just from column 2 in example file: abcd abcd1 abcd abcd2 abcd abcd3 to get output: abcd 1 abcd 2 abcd 3 Thank you!:) (4 Replies)
Discussion started by: auburn
4 Replies

7. Shell Programming and Scripting

Remove line based on string and put new line with parameter

Hi Folks, I am new to ksh, i have informatica parameter file that i need to update everyday with shell script. i need your help updating this file with new parameters. sample data $$TABLE1_DATE=04-27-2011 $$TABLE2_DATE=04-23-2011 $$TABLE3_DATE=03-19-2011 .......Highligned... (4 Replies)
Discussion started by: victor369
4 Replies

8. Shell Programming and Scripting

Remove line with specific character

HI Input :- Aog:0rt__dev_8 LAAXU24 vs.3 LAA40l0 ** LAAXU241 ** Output :- Aog:0rt__dev_8 LAAXU24 vs.3 Delete the line with ** (3 Replies)
Discussion started by: pareshkp
3 Replies

9. Shell Programming and Scripting

Remove duplicate consecutive lines with specific string

Hello, I'm trying to remove the duplicate consecutive lines with specific string "WARNING". File.txt abc; WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 bcd; abc; 123 123 123 WARNING 1234 WARNING 2345 WARNING 2345 efgh; (6 Replies)
Discussion started by: Mannu2525
6 Replies
metahs(1M)                                                System Administration Commands                                                metahs(1M)

NAME
metahs - manage hot spares and hot spare pools SYNOPSIS
/usr/sbin/metahs [-s setname] -a all component /usr/sbin/metahs [-s setname] -a hot_spare_pool [component] /usr/sbin/metahs [-s setname] -d hot_spare_pool [component] /usr/sbin/metahs [-s setname] -d all component /usr/sbin/metahs [-s setname] -e component /usr/sbin/metahs [-s setname] -r hot_spare_pool component-old /usr/sbin/metahs [-s setname] -r all component-old component-new /usr/sbin/metahs [-s setname] -i [hot_spare_pool...] DESCRIPTION
The metahs command manages existing hot spares and hot spare pools. It is used to add, delete, enable, and replace components (slices) in hot spare pools. Like the metainit command, the metahs command can also create an initial hot spare pool. The metahs command does not replace a component of a metadevice. This function is performed by the metareplace command. Hot spares are always in one of three states: available, in-use, or broken. Available hot spares are running and ready to accept data, but are not currently being written to or read from. In-use hot spares are currently being written to and read from. Broken hot spares are out of service and should be repaired. The status of hot spares is displayed when metahs is invoked with the -i option. Solaris Volume Manager supports storage devices and logical volumes, including hot spares, greater than 1 terabyte (TB) when Solaris 10 is running a 64-bit kernel. If a system with large volumes or hot spares is rebooted under a 32-bit Solaris 10 kernel, the large volumes are visible through metastat output, but they cannot be accessed, modified or deleted, and no new large volumes can be created. Any volumes or file systems on a large volume in this situation are also unavailable. If a system with large volumes is rebooted under a version of Solaris prior to Solaris 10, Solaris Volume Manager will not start. All large volumes must be removed before Solaris Volume Manager runs under another version of the Solaris Operating Environment. OPTIONS
Root privileges are required for any of the following options except -i. The following options are supported: -a all component Add component to all hot spare pools. all is not case sensitive. -a hot_spare_pool [component] Add the component to the specified hot_spare_pool. hot_spare_pool is created if it does not already exist. -d all component Delete component from all the hot spare pools. The component cannot be deleted if it is in the in-use state. -d hot_spare_pool [component] Delete hot_spare_pool, if the hot_spare_pool is both empty and not referenced by a metadevice. If component is specified, it is deleted from the hot_spare_pool. Hot spares in the in-use state cannot be deleted. -e component Enable component to be available for use as a hot spare. The component can be enabled if it is in the broken state and has been repaired. -i [hot_spare_pool...] Display the status of the specified hot_spare_pool or for all hot spare pools if one is not specified. -r all component-old component-new Replace component-old with component-new in all hot spare pools which have the component associated. Components cannot be replaced from any hot spare pool if the old hot spare is in the in-use state. -r hot_spare_pool component-old component-new Replace component-old with component-new in the specified hot_spare_pool. Components cannot be replaced from a hot spare pool if the old hot spare is in the in-use state. -s setname Specify the name of the diskset on which metahs works. Using the -s option causes the command to perform its administrative function within the specified diskset. Without this option, the command performs its function on local hot spare pools. OPERANDS
The following operands are supported: component The logical name for the physical slice (partition) on a disk drive, such as /dev/dsk/c0t0d0s2. hot_spare_pool Hot spare pools must be of the form hspnnn, where nnn is a number in the range 000-999. EXAMPLES
Example 1: Adding a Hot Spare to a Hot Spare Pool The following example adds a hot spare /dev/dsk/c0t0d0s7 to a hot spare pool hsp003: # metahs -a hsp003 c0t0d0s7 When the hot spare is added to the pool, the existing order of the hot spares already in the pool is preserved. The new hot spare is added at the end of the list of hot spares in the hot spare pool specified. Example 2: Adding a Hot Spare to All Currently Defined Pools This example adds a hot spare to the hot spare pools that are currently defined: # metahs -a all c0t0d0s7 The keyword all in this example specifies adding the hot spare, /dev/dsk/c0t0d0s7, to all the hot spare pools. Example 3: Deleting a Hot Spare This example deletes a hot spare, /dev/dsk/c0t0d0s7, from a hot spare pool, hsp003: # metahs -d hsp003 c0t0d0s7 When you delete a hot spare, the position of the remaining hot spares in the pool changes to reflect the new order. For instance, if in this example /dev/dsk/c0t0d0s7 were the second of three hot spares, after deletion the third hot spare would move to the second position. Example 4: Replacing a Hot Spare This example replaces a hot spare that was previously defined: # metahs -r hsp001 c0t1d0s0 c0t3d0s0 In this example, the hot spare /dev/dsk/c0t1d0s0 is replaced by /dev/dsk/c0t3d0s0. The order of the hot spares does not change. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWmdu | +-----------------------------+-----------------------------+ SEE ALSO
mdmonitord(1M), metaclear(1M), metadb(1M), metadetach(1M), metainit(1M), metaoffline(1M), metaonline(1M), metaparam(1M), metarecover(1M), metarename(1M), metareplace(1M), metaroot(1M), metaset(1M), metassist(1M), metastat(1M), metasync(1M), metattach(1M), md.tab(4), md.cf(4), mddb.cf(4), md.tab(4), attributes(5), md(7D) Solaris Volume Manager Administration Guide WARNINGS
Do not create large (>1 TB) volumes if you expect to run the Solaris Operating Environment with a 32-bit kernel or if you expect to use a version of the Solaris Operating Environment prior to Solaris 10. SunOS 5.10 8 Aug 2003 metahs(1M)
All times are GMT -4. The time now is 12:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy