Sponsored Content
Full Discussion: Delete multiple lines w/ sed
Top Forums Shell Programming and Scripting Delete multiple lines w/ sed Post 38755 by criglerj on Thursday 24th of July 2003 10:44:02 PM
Old 07-24-2003
If you are using sh/ksh/bash/zsh:
Code:
sed '1d
5d' filex

I.e., you need the line break.

The awk version is a bit more direct:
Code:
awk 'NR!=1 && NR!=5' filex

This takes advantage of the default awk action, which is to print the input line. This method simply accepts all lines except 1 and 5.

It can be generalized:
Code:
#!/bin/sh
while getopts s: arg; do
    case $arg in
    s)  skip="$OPTARG"
    esac
done
shift `expr $OPTIND - 1`
awk -v "sl=$skip" 'BEGIN {
        split(sl, a, ",")
        for (i in a) skip[a[i]] = 1
    }
!skip[NR]' "$1"




Last edited by criglerj; 07-25-2003 at 12:08 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to delete multiple lines in a file.

Hi, I'm new to this forum, and searched through the previous posts, but didn't see anything close enough to what i'm looking for. I have a radius file like this: testone Password = "11111" Service-Type = "Framed-User", Session-Timeout =... (6 Replies)
Discussion started by: kangdom
6 Replies

2. UNIX for Dummies Questions & Answers

Delete multiple lines containting a variable string using SED.

Good morning, Novice scripter in Unix here, and I've run into and sed task I can't quite wrap my head around. I'm pulling my hair out fast enough as it is and thought I would go to the knowledge bank. I have a sorted file that I'm trying to trim down by deleting any line whose first few... (2 Replies)
Discussion started by: selkirk
2 Replies

3. Shell Programming and Scripting

using sed command to delete a string spanning multiple lines

file1 contains the following data sssssssssss firstline secondline pppppppppp ssssssssss Using sed comamnd i am trying to delete firtsline secondline. so, output should be sssssssssss pppppppppp ssssssssss I tried in the following the way, but it is not working. sed ... (9 Replies)
Discussion started by: radha.kalivar
9 Replies

4. Shell Programming and Scripting

sed problem - delete all lines until a match on 2 lines

First of all, I know this can be more eassily done with perl or other scripting languages but, that's not the issue. I need this in sed. (or wander if it's possible ) I got a file (trace file to recreate the control file from oracle for the dba boys) which contains some lines another line... (11 Replies)
Discussion started by: plelie2
11 Replies

5. Shell Programming and Scripting

Delete multiple lines from a file

Hi, I'm trying to delete some entry's, the source is a file1, from file2 what I have until now is this file1 : 68255706,234200801053269,447916926187,8944200006353029289F 73495477,234200101579319,447861769299,8944200006852033303F file2: 353851164675 NEW : 272050001241889 -ok ... (10 Replies)
Discussion started by: BlueRay86
10 Replies

6. Shell Programming and Scripting

Delete multiple lines in a file

The high level requirement is as follows: I have a file which has multiple line starting with pattern (which is fixed say "Hello" and i need to search for one more pattern in that line which starts with "Hello" and if the pattern matches, i need to delete lines from that line to the next line... (5 Replies)
Discussion started by: KeerthiReddy
5 Replies

7. Shell Programming and Scripting

sed to conditionally delete multiple lines

Hello I'd like to remove any line in an output file that is preceded by one or more warning messages (each warning is on a separate line). Example : WARNING: Estimation of lower confidence limit of \rho failed; setting it to 0. 822 28447 ... (4 Replies)
Discussion started by: jossojjos
4 Replies

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

9. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

10. UNIX for Beginners Questions & Answers

Delete multiple lines between blank lines containing two patterns

Hi all, I'm looking for a way (sed or awk) to delete multiple lines between blank lines containing two patterns ex: user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 16... (3 Replies)
Discussion started by: ce9888
3 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 08:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy