Sponsored Content
Top Forums Shell Programming and Scripting retaining only the second line with a pattern and deleting all others Post 302568919 by goodbenito on Friday 28th of October 2011 03:42:33 PM
Old 10-28-2011
retaining only the second line with a pattern and deleting all others

Hi,

I have a file:

5 T1AxialPremosaic ok 512 448 23 1 284000-000005-000001.dcm
6 T2_SPACE ok 256 256 176 1 465000-000006-000001.dcm
7 FLAIRmosaic ok 512 432 23 1 748000-000007-000001.dcm
8 T2_SPACE ok 256 256 1 171000-000008-000001.dcm
9 T2_SPACE ok 256 256 1 218000-000009-000001.dcm
32 T1AxialPostmosaic ok 512 448 23 1 836000-000032-000001.dcm
33 MEMPRAGE ok 256 256 704 1 408000-000033-000001.dcm
34 MEMPRAGE ok 256 256 176 1 767000-000034-000001.dcm
35 MEMPRAGE ok 256 256 1 380000-000035-000001.dcm
36 MEMPRAGE ok 256 256 1 178000-000036-000001.dcm

...and I would like to retain only the second line with the pattern MEMPRAGE (preferably using just RAGE and in a case-insensitive manner). I've tried different things with awk:

Code:
awk 'tolower($0) ~ /rage/&&c++>0 {next} 1' inputfile

but for this guy (above), I don't know how to keep only the second occurrence. I've also tried various plays on this one-liner:

Code:
awk '(substr($0,8,4)!="RAGE")||(NR<1)' inputfile

But this isn't quite right either. The bottom line is that I don't understand awk, sed or grep well enough to get it done quickly. Any help would be greatly appreciated. Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

prom in deleting a pattern

hi guys, i have a directory.inside that so many directories and files are there.i want to search the complete directory for a pattern in all the .txt files.if i will find that pattern then i want to delete that pattern from that file. please help me out. i want it urgent (18 Replies)
Discussion started by: suvendu4urs
18 Replies

2. UNIX for Dummies Questions & Answers

find pattern delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: W/D FRM CHK 00 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (1 Reply)
Discussion started by: nickg
1 Replies

3. Shell Programming and Scripting

find pattern, delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: FRM CHK 0000 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (4 Replies)
Discussion started by: nickg
4 Replies

4. Shell Programming and Scripting

deleting a pattern from a file

say i have a file with the following contents 0x20 0x20 0xc23886 > 0xc12354 > 0xc567555555 i want to delete "> " pattern and keep the rest of the file (6 Replies)
Discussion started by: lassimanji
6 Replies

5. Shell Programming and Scripting

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

6. Shell Programming and Scripting

Deleting pattern without removing line

I am trying to delete a pattern without removing line. I searched a lot in this forum and using those I could come up with sed command but it seems that command does not work. Here's how my file looks like: 1 ./63990 7 1171 ./63990 2 2425 ./63990 9 2539 ./63990 1 3125 ./63990 1 10141... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Deleting a pattern in UNIX without deleting the entire line

Hi I have a file: r58778.3|SOURCES={KEY=f665931a...,fw,221-705}|ERRORS={16_1:T,30_1:T,56_1:C,57_1:T,59_1:A,101_1:A,115:-,158_1:C,186_1:A,204:-,271_1:T,305:-,350_1:C,368_1:G,442_1:C,472_1:G,477_1:A}|SOURCE_1="Contig_1092402550638"(f665931a359e36cea0976db191ff60ff09cc816e) I want to retain... (15 Replies)
Discussion started by: Alyaa
15 Replies

9. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

10. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
HDFTOR8(1)						      General Commands Manual							HDFTOR8(1)

NAME
hdftor8 - extract 8-Bit raster images and palettes from HDF file SYNOPSIS
hdftor8 hdf-file [-i] [-v] [-r raster-image-file] [-p pallette-file] DESCRIPTION
hdftor8 extracts the raster images and/or palettes from an HDF file and stores them in one file that contains the raster image data and an- other that contains the palette data. The names given for the raster image and palette files are interpreted by hdftor8 as follows: For each raster image file, the file name is given the extension ".#.@.%", where "#" represents the raster image number from the HDF file, "@" represents the x-dimension of the raster image, and "%" represents the y-dimension of the raster image. For each palette file, the file name is given the extensions ".#", where "#" represents the palette number from the HDF format file. If no name is given for the raster image file, the default name "img.#.@.%" is assigned, where "#", "@", and "%" are as defined in the pre- ceding paragraph. The default name for a palette file is "pal.#". OPTIONS
-i Execute the program in interactive mode. -v Execute in verbose mode. Display diagnostic messages during the session. -r raster-image-file Specify the name of the raster image file. -p pallette-file Specify the name of the palette file. EXAMPLES
A file named "denm.hdf" contains three 512 x 256 raster images and three palettes. To store these images and palettes in separate raster image and palette files, use the following hdftor8 command: hdftor8 denm.hdf Six files are created, named "img1.512.256", "img2.512.256", "img3.512.256", "pal.1", "pal.2", and "pal.3". SEE ALSO
r8tohdf(1), hdf(5) November 6, 1999 HDFTOR8(1)
All times are GMT -4. The time now is 10:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy