delete using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete using sed
# 1  
Old 02-19-2010
delete using sed

hi ,
i need to delete all the lines in a file except a line which starts with the letter SP
# 2  
Old 02-19-2010
Code:
grep '^SP' file

or:

Code:
awk '/^SP/' file

# 3  
Old 02-19-2010
hi , thankz for ur reply ..
But i need to do the same with sed .
# 4  
Old 02-19-2010
Quote:
Originally Posted by mhdmehraj
hi , thankz for ur reply ..
But i need to do the same with sed .
Why?

Is grep or awk not good enough or is this a homework question?
# 5  
Old 02-19-2010
Hi .. Its gud ,

But we are using it on windows , So we have only sed utility....
# 6  
Old 02-19-2010
Should be something like (on a UNIX OS):

Code:
sed -n '/^SP/p' file


Last edited by Franklin52; 02-19-2010 at 08:23 AM.. Reason: correcting pattern
# 7  
Old 02-19-2010
Code:
sed '/^SP/!d' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed to delete ^M

I am trying to use sed to delete the ^M at the end of the line and when i pass a file './asciiFix.sh wintest.txt' I get an error saying sed: can't read : no such file or dir. Can someone give me a pointer as to what I am doing wrong? #!/bin/sh if file "$@" | grep "with CRLF"; then echo... (5 Replies)
Discussion started by: kwatt019
5 Replies

2. Shell Programming and Scripting

sed delete

I am not able to analyze the below code.. What I expected is that DELETED will be replaced with the first field in every line.But after giving a try, the output was different. Can anyone pleas analyze and explain the code in detail? Many thanks... $ sed 's/* /DELETED /g' g1.txt > g4.txt... (2 Replies)
Discussion started by: giridhar276
2 Replies

3. Shell Programming and Scripting

sed delete range

Hi I would like to delete ranges of text from an html file; In the sentence; aqua>Stroomprobleem in Hengelo verholpen <a href="107-01.html"><font color=yellow>107</a> With several sentences like this in that file, where the text between <a href a> varies, so it needs to be deleted in the... (2 Replies)
Discussion started by: mdop
2 Replies

4. Shell Programming and Scripting

sed delete option

I have tried doing this to delete some lines: sed '1,10d' file Now I want to specify a variable as a line number for example: lastline=wc -l file linestart=$lastline - 20 sed '$linestart,$lastlined' file but this will give error: sed: -e expression #1, char 3: extra characters after... (4 Replies)
Discussion started by: zorrox
4 Replies

5. Shell Programming and Scripting

sed - delete everything until the first digit comes up

Hi, I have a text file with content as follows: bla foo3200492 comment on this: 3900302 here comes the teddy 12 all I need is: 3200492 3900302 12 So I need the correct "sed" command to delete everything until the first number. I am not a regex expert, because I have to... (3 Replies)
Discussion started by: mcW
3 Replies

6. Shell Programming and Scripting

sed-delete

Guys, file1: test \ 123 cat file1 | sed '/test \/d' ---- does not work I have to remove the line "test \" in file1 can somebody help ? (7 Replies)
Discussion started by: giri_luck
7 Replies

7. UNIX for Dummies Questions & Answers

Delete ^ using sed

Hi All, I am very new to UNIX... I was trying to delete ^ from a file and save it with different name... The version is AIX 5.3 The input file is in this directory /a/b The Input file name is o9876.out I want the output file in same path with different name like ABC.txt... (5 Replies)
Discussion started by: us_pokiri
5 Replies

8. UNIX for Dummies Questions & Answers

Sed: Append and Delete?

I think it should be obvious what I'm trying to do from my command, but just to be sure it's clear, I'm trying to append 2 lines after a matched line and then delete 2 other lines within a file. I'd like to do it in 1 line if possible. This code isn't working, but hopefully it's just a syntax... (0 Replies)
Discussion started by: earnstaf
0 Replies

9. Shell Programming and Scripting

sed help - delete last 2 lines.

I have been reading through the sed one liners, trying to understand what is happening. # delete the last 2 lines of a file sed 'N;$!P;$!D;$d' The above will delete the last 2 line of a file. I tried analyzing what happens. And I got lost :( This is what I understood so far from the... (2 Replies)
Discussion started by: vino
2 Replies

10. UNIX for Dummies Questions & Answers

Using sed to delete a string?

Hi all! Here is my problem : I have a string like the following : 20030613170404;BAN_CAV ; starting script Loader.sh on ; 13/06/2003 at ; 17;04;03 I want to eraze all characters located after "Loader.sh", because there are unuseful. I tried to use sed...but it didnt work....i guess i... (1 Reply)
Discussion started by: HowardIsHigh
1 Replies
Login or Register to Ask a Question