Question about SED for excluding lines

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Question about SED for excluding lines
# 8  
Old 11-23-2007

sorry to bother again, but it still doesn't work. I'm using SunOS 5.8 and when I run the command you suggested I get an errors

% sed --version

gives "ksh: %: not found"

man sed doesn't return the version number either. Here is what I get :

udkoapp1p-oadppoap > man sed
Reformatting page. Please Wait... done

User Commands sed(1)

sed - stream editor

/usr/bin/sed [ -n ] script [ file ... ]

/usr/bin/sed [ -n ] [ -e script ] ... [ -f script_file
] ... [ file ... ]

/usr/xpg4/bin/sed [ -n ] script [ file ... ]

/usr/xpg4/bin/sed [ -n ] [ -e script ] ... [
-f script_file ] ... [ file ... ]

The sed utility is a stream editor that reads one or more
text files, makes editing changes according to a script of
editing commands, and writes the results to standard output.
The script is obtained from either the script operand

I tried using awk as you wrote, but I also get an error:
awk: syntax error near line 3
awk: illegal statement near line 3

# 9  
Old 11-23-2007
Hi, greg.

The sed response you received means that the sed that is in your path is not the GNU sed. You can research this farther to see if you or your SA can acquire GNU sed for your use.

As regards the awk, I have read elsewhere in this forum that one is advised to:
Use nawk or /usr/xpg4/bin/awk on Solaris.
As an aside, I have become disappointed with Solaris. It seems as if the utilities provided have not kept up with the GNU/Linux utilities, and consequently Solaris utilities lack many useful features. This does not mean that GNU/Linux is perfect -- I often find myself writing utilities that provide features that GNU/Linux omits.

I hope this works out well for you ... cheers, drl
# 10  
Old 11-23-2007
Here is a sed script which should work on all versions of sed


sed '
/package/ {
    /PRAGMA/ b skip
    /END/ b skip
}'  < infile > outfile

# 11  
Old 11-23-2007

Confirmation: the modification posted by fpmurphy worked on the GNU/Linux that I noted earlier, and I tried it on a BSD box, sed version (from strings):
@(#) Copyright (c) 1992, 1993
        The Regents of the University of California.  All rights reserved.
@(#)main.c      8.2 (Berkeley) 1/3/94

and it worked there as well. Nice work, fpmurphy.

The awk worked correctly on BSD, too ... cheers, drl
# 12  
Old 11-23-2007

thanks for your replies guys.

The script proposed by fpmurphy worked very well for me too. All the occurences were replaced except the ones that were on the lines containing either "PRAGMA" or "END". Thank you for your help.

Regarding the UNIX system I'm using, I have no say, I'm just a mere programmer who must toe the line Smilie

Thanks again for help,

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

2. Shell Programming and Scripting

ksh sed - Extract specific lines with mulitple occurance of interesting lines

Data file example I look for primary and * to isolate the interesting slot number. slot=`sed '/^primary$/,/\*/!d' filename | tail -1 | sed s'/*//' | awk '{print $1" "$2}'` Now I want to get the Touch line for only the associate slot number, in this case, because the asterisk... (2 Replies)
Discussion started by: popeye
2 Replies

3. Shell Programming and Scripting

Stripping ret of the lines in a file (sed question)

Hi all, I didn't use SED for 20 years and was never an expert. So my current knowledge is about zero. Please be patient with me. I'm neither a native speaker. I have a huge dictionary file and want the rest of the lines stripped. Everything after (and including) the "/" should be stripped. I... (2 Replies)
Discussion started by: Hinnerk2005
2 Replies

4. Shell Programming and Scripting

Use sed to print first n lines and last n lines of an output.

Use sed to print first n lines and last n lines of an output. For example: n=10 Can it be done? Thanks. (7 Replies)
Discussion started by: carloszhang
7 Replies

5. UNIX for Dummies Questions & Answers

Excluding a specific column from sed replacement

Hi, I would like to replace all 0's to 1's throughout my text file. However I do not want column 3 altered. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

6. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

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

8. Shell Programming and Scripting

sed show lines text between 2 blank lines

I have a file like blah blah blah blah this is the text I need, which might be between 1-4 lines, but always has a blank line above and below it, and is at the end of the text file the code tags don't show the trailing blank line. I started by deleting the last blank line with: ... (2 Replies)
Discussion started by: unclecameron
2 Replies

9. Shell Programming and Scripting

print lines up to pattern excluding pattern

11 22 33 44 55 66 77 When pattern 55 is met, print upto it, so output is 11 22 33 44 (1 Reply)
Discussion started by: anilcliff
1 Replies

10. 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
Login or Register to Ask a Question