Sponsored Content
Top Forums Shell Programming and Scripting Remove if the above line matches pattern Post 302402775 by alister on Wednesday 10th of March 2010 03:36:04 PM
Old 03-10-2010
Hi, spacegoose:

Code:
$ cat data
foo: bar
foo: moo
blarg
i am on vacation
foo: goose
foo: lucy
foo: moose
foo: stucky
groover@monkey.org
foo: bozo
grimace@gonzo.net
dear sir - blargo blargo
foo: goon
foo: sloppy
foo: saudi
gimme gimme gimme
i have something for you
foo: mad
foo: happy
foo: foo

Using SED:
Code:
$ cat spacegoose.sed
#n
/^foo:/!{
    :top
    p
    /^foo:/!{
        n
        b top
    }
}

$ sed -f spacegoose.sed data
blarg
i am on vacation
foo: goose
groover@monkey.org
foo: bozo
grimace@gonzo.net
dear sir - blargo blargo
foo: goon
gimme gimme gimme
i have something for you
foo: mad

If you require a blank line after each sequence:
Code:
$ cat spacegooseLF.sed
#n
/^foo:/!{
    :top
    p
    /^foo:/!{
        n
        b top
    }
    s/.*//p
}

$ sed -f spacegooseLF.sed data
blarg
i am on vacation
foo: goose

groover@monkey.org
foo: bozo

grimace@gonzo.net
dear sir - blargo blargo
foo: goon

gimme gimme gimme
i have something for you
foo: mad

Using AWK:
Code:
awk '!/^foo:/,/^foo/'

If you require a blank line after each sequence:
Code:
awk '!/^foo:/,/^foo/{print; if(/^foo/)print ""}'

Cheers,
Alister

Last edited by alister; 03-10-2010 at 05:11 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print line if first Field matches a pattern

Hi All, I would like my code to be able to print out the whole line if 1st field has a dot in the number. Sample input and expected output given below. My AWK code is below but it can;t work, can any expert help me ? Thanks in advance. {if ($1 ~ /*\.*/) { print $0 }} Input: ... (2 Replies)
Discussion started by: Raynon
2 Replies

2. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

3. Shell Programming and Scripting

Perl line count if it matches a pattern

#!/usr/bin/perl use Shell; open THEFILE, "C:\galileo_integration.txt" || die "Couldnt open the file!"; @wholeThing = <THEFILE>; close THEFILE; foreach $line (@wholeThing){ if ($line =~ m/\\0$/){ @nextThing = $line; if ($line =~ s/\\0/\\LATEST/g){ @otherThing =... (2 Replies)
Discussion started by: nmattam
2 Replies

4. Shell Programming and Scripting

NAWK to remove lines that matches a specific pattern

Hi, I have requirement that I need to split my input file into two files based on a search pattern "abc" For eg. my input file has below content abc defgh zyx I need file 1 with abc and file2 with defgh zyx I can use grep command to acheive this. But with grep I need... (8 Replies)
Discussion started by: sbhuvana20
8 Replies

5. Shell Programming and Scripting

remove contents including the tag if pattern matches

Hi all, Can anyone help me on this. I have several WP sites that are affected by sql injections. But the contents are different as follows western union india belgaum western union india bolegaon western union india barhaj western union india budhana western union india belda western... (6 Replies)
Discussion started by: sanjuabraham
6 Replies

6. Shell Programming and Scripting

[Solved] Finding the next line when a pattern matches

Hi I have a file like this Record 182: Rejected No Data found Record 196: Rejected File Not Found Record 202: Rejected Invalid argument Record 212: Rejected Bad data My requirement is to search for the value "Record" and if found, then return the next line of it. So,... (3 Replies)
Discussion started by: mr_manii
3 Replies

7. Shell Programming and Scripting

Search a pattern in a line and remove another pattern

Hi, I want to search a pattern in a text file and remove another pattern in that file. my text file look like this 0.000000 1.970000 F 303 - 1.970000 2.080000 VH VH + 2.080000 2.250000 VH VH + 2.250000 2.330000 VH L - 2.330000 2.360000 F H + 2.360000 2.410000 L VL - 2.410000 ... (6 Replies)
Discussion started by: sreejithalokkan
6 Replies

8. Shell Programming and Scripting

Count number of pattern matches per line for all files in directory

I have a directory of files, each with a variable (though small) number of lines. I would like to go through each line in each file, and print the: -file name -line number -number of matches to the pattern /comp/ for each line. Two example files: cat... (4 Replies)
Discussion started by: pathunkathunk
4 Replies

9. Shell Programming and Scripting

Remove entire line from a file if 1st column matches a pattern

I have one requirement to delete all lines from a file if it matches below scenario. File contains three column. Employee Number, Employee Name and Employee ID Scenario is: delete all line if Employee Number (1st column) contains below 1. Non-numeric Employee Number 2. Employee Number that... (3 Replies)
Discussion started by: anshu ranjan
3 Replies

10. Shell Programming and Scripting

How to get a 1st line which matches the particular pattern?

Hi all, I have file on which I do grep on "/tmp/data" then I get 5 lines as dir Path: /tmp/data/20162343134 Starting to listen on ports logging: -- Moving results files from local storage: /tmp/resultsFiles/20162343134/*.gz to NFS: /data/temp/20162343134/outgoing from above got to get... (7 Replies)
Discussion started by: girijajoshi
7 Replies
UNCPK(1)						      General Commands Manual							  UNCPK(1)

NAME
uncpk - manage c64 cpk archives SYNOPSIS
uncpk [OPTION]... FILE... DESCRIPTION
uncpk is an archive tool for Commodore 64 .cpk-format archives. OPTIONS
c Create an archive. x Extract from an archive. l List contents of archive. a Add a file to the archive. v Verbose output. --help Show summary of options. --version Show version of program. EXAMPLES
uncpk c foo.cpk bar Create archive foo.cpk with the single file bar inside it. uncpk a foo.cpk bar Add file bar to archive foo.cpk (which must already exist). uncpk x foo.cpk Extract all files from archive foo.cpk. uncpk l foo.cpk List contents of archive foo.cpk. SEE ALSO
file65(1), ldo65(1), printcbm(1), reloc65(1), dxa(1), xa(1) AUTHOR
This manual page was written by David Weinehall <tao@acc.umu.se> and Cameron Kaiser <ckaiser@floodgap.com>. Original xa package (C)1989-1997 Andre Fachat. Additional changes (C)1989-2006 Andre Fachat, Jolse Maginnis, David Weinehall and Cameron Kaiser. The current maintainer is Cameron Kaiser. WEBSITE
http://www.floodgap.com/retrotech/xa/ 11 April 2006 UNCPK(1)
All times are GMT -4. The time now is 02:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy