Sponsored Content
Top Forums Shell Programming and Scripting Remove a range of lines from a file using sed Post 302592968 by Andy82 on Wednesday 25th of January 2012 10:31:04 AM
Old 01-25-2012
Thanks for the feedback. The command is nearly working. I am still having an issue getting sed to stop searching when it finds the second string in the range.

What it should do is.
1. Search the file for the first string in the range. This string will have a unique value for each occurrence in the file. So I am using a variable.
2. Take the lines from the file under the above string until it gets to the second occurrence of the second string in the range. The second string is no unique in the file. This is why I want sed to stop searching when it finds it for the second time after it has found the first string.

File looks like this

1st String. Remove 1
Data
Data
2nd String
2nd String
1st String. Do not remove
Data
Data
2nd String
2nd String
1st String Remove 2
Data
Data
2nd String
2nd String

When I am finished I would want the file to look like

1st String
Data
Data
2nd String
2nd String

When the command runs it removes everything from the file under 1st String. Remove 1

Is this even possible to do in sed? Or should I be looking into using awk. I used sed as I have no experience in Awk and had some in sed.
The code that I am using is as in the second post above

Code:
 sed '/'"${var[$count]}"'/,/'"Con       ST"'q/d' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove range part of a file with sed

Hello, I would like to remove a range from a file with sed or any script command that is appropriate The section start by and finish by and I would like to keep line Could you tell me which command I should type ? Thanks a lot, Franck My input file is like this... (1 Reply)
Discussion started by: mfranck
1 Replies

2. Shell Programming and Scripting

Remove strings within range using sed

Hey folks I have a big file that contains junk data between the tags <point> and </point> and I need to delete it (including `<point>' and `</point>'). i.e. a = 1 <point> 123123 2342352 234231 234256 </point> print a needs to become a = 1 print a I'm certain that this is a... (10 Replies)
Discussion started by: ksk
10 Replies

3. Shell Programming and Scripting

grep/sed to remove lines in file

Hi, I have a file with values, file1: BELL-1180-1180-81|577:1017| BELL-1180-1180-81|jm10i-auto-stub1/577:102| BELL-1180-1180-81|jm10i-auto-stub1/577:101| BELL-1180-1180-81|jm10i-auto-stub1/577:1700| BELL-1180-1180-81|jm10i-auto-stub1/577:1699| I need to remove the lines which has... (9 Replies)
Discussion started by: giri_luck
9 Replies

4. Shell Programming and Scripting

Sed print range of lines between line number and pattern

Hi, I have a file as below This is the line one This is the line two <\XMLTAG> This is the line three This is the line four <\XMLTAG> Output of the SED command need to be as below. This is the line one This is the line two <\XMLTAG> Please do the need to needful to... (4 Replies)
Discussion started by: RMN
4 Replies

5. Shell Programming and Scripting

sed filtering lines by range fails 1-line-ranges

The following is part of a larger project and sed is (right now) a given. I am working on a recursive Korn shell function to "peel off" XML tags from a larger text. Just for context i will show the complete function (not working right now) here: function pGetXML { typeset chTag="$1" typeset... (5 Replies)
Discussion started by: bakunin
5 Replies

6. Shell Programming and Scripting

Using sed in a loop/to remove lines contained in variable from file

I've tried numerous commands, but I am not sure how to use sed in a loop. This is what I have: VARZ contains CARD_FILE_LIST and it also contains CARD_FILE_LIST2 so echo "$VARZ" CARD_FILE_LIST CARD_FILE_LIST2 I have a file with 60 lines in /tmp/testfile it and I want those lines deleted... (3 Replies)
Discussion started by: newbie2010
3 Replies

7. Shell Programming and Scripting

sed to remove all lines in file that are not .vcf.gz extention

I am trying to use sed to remove all lines in a file that are nor vcf.gz. The sed below runs but returns all the files with vcf.gz in them, rather then just the ones that end in only that extention. Thank you :). file ... (9 Replies)
Discussion started by: cmccabe
9 Replies

8. Shell Programming and Scripting

How to remove repetitive lines in a file with sed?

Hello, My goal is the make all x times repeated lines into a single line. I need to attain the expected output with sed -i , I need to overwrite the MyFile MyFile: Hello World Welcome Hello World Welcome Back This is my test Expected output: Hello World Welcome Welcome Back This is... (6 Replies)
Discussion started by: baris35
6 Replies

9. Shell Programming and Scripting

sed or awk to remove specific column to one range

I need to remove specific column to one range source file 3 1 000123456 2 2 000123569 3 3 000123564 12 000123156 15 000125648 128 000125648 Output required 3 000123456 2 000123569 3 000123564 12 000123156 15 000125648 128 000125648 (6 Replies)
Discussion started by: ranjancom2000
6 Replies

10. UNIX for Beginners Questions & Answers

Sed/awk to delete a regex between range of lines

Hi Guys I am looking for a solution to one problem to remove parentheses in a range of lines. Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj;... (5 Replies)
Discussion started by: kshitij
5 Replies
XtErrorMsg(3)						    XT COMPATIBILITY FUNCTIONS						     XtErrorMsg(3)

NAME
XtErrorMsg, XtSetErrorMsgHandler, XtWarningMsg, XtSetWarningMsgHandler - high-level error handlers SYNTAX
void XtErrorMsg(String name, String type, String class, String default, String *params, Cardinal *num_params); void XtSetErrorMsgHandler(XtErrorMsgHandler msg_handler); void XtSetWarningMsgHandler(XtErrorMsgHandler msg_handler); void XtWarningMsg(String name, String type, String class, String default, String *params, Cardinal *num_params); ARGUMENTS
class Specifies the resource class. default Specifies the default message to use. name Specifies the general kind of error. type Specifies the detailed name of the error. msg_handler Specifies the new fatal error procedure, which should not return or the nonfatal error procedure, which usually returns. num_params Specifies the number of values in the parameter list. params Specifies a pointer to a list of values to be stored in the message. DESCRIPTION
The XtErrorMsg function has been superceded by XtAppErrorMsg. The XtSetErrorMsgHandler function has been superceded by XtAppSetErrorMsgHandler. The XtSetWarningMsgHandler function has been superceded by XtAppSetWarningMsgHandler. The XtWarningMsg function has been superceded by XtAppWarningMsg SEE ALSO
XtAppErrorMsg(3) X Toolkit Intrinsics - C Language Interface Xlib - C Language X Interface X Version 11 libXt 1.1.3 XtErrorMsg(3)
All times are GMT -4. The time now is 11:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy