Sed find exact string and delete line with variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed find exact string and delete line with variable
# 1  
Old 04-24-2012
Sed find exact string and delete line with variable

All,
I am trying to read in a variable and search a file then delete based on that string, but i want to match exact word.

This works but it matches all, i don't want to match anthing that contains the string, just the exact string.
Code:
sed -i "/$feedname/d" file

I tried
Code:
sed "/\<$feedname>\/d" file

but I get an unterminated regec error. Any help?

Last edited by Scrutinizer; 04-24-2012 at 04:28 PM.. Reason: code tags
# 2  
Old 04-24-2012
> and \ are reversed. Mosts seds do not understand this syntax BTW.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help with how to search a file for a variable string and delete that line

Hi, I have a working script. It does what I am intending it to but a bit confused whether the sed part is supposed to be working or not. Further down is the script with the sed part that should have been working but not and the grep -v part which is the workaround that I am using at the... (10 Replies)
Discussion started by: newbie_01
10 Replies

2. Shell Programming and Scripting

How to find string and delete before just in line?

Hello, When my lines contain question mark, I use below command to delete the portion of the matching line coming after question mark: sed 's/?.*//' SampleFile SampleFile: helloworldfirstline?mdksmyymsss hellosecondlineworld?mdksmkkmsss thirdhelloworld?mdksmccmsss Output:... (2 Replies)
Discussion started by: baris35
2 Replies

3. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

4. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

5. Shell Programming and Scripting

delete the line with a particular string in a file using sed command.

Hello, I want to delete all lines with given string in file1 and the string val is dynamic. Can this be done using sed command. Sample: vars="test twinning yellow" for i in $vars do grep $i file1 if then echo "Do Nothing" else sed `/$i/d` file1 fi done Using the above... (5 Replies)
Discussion started by: PrasadAruna
5 Replies

6. Shell Programming and Scripting

Need sed help: find regex and if the next next line is blank, delete both

I've got a report I need to make easier to read Using sh on HP-UX 11.12. In short, I want to search for a regular expression and when found, examine the next line to see if it's blank. If so, then delete both lines. If not blank, move on to the next regexp. Repeat. So far I've got: ... (7 Replies)
Discussion started by: Scottie1954
7 Replies

7. Shell Programming and Scripting

sed to find pattern and delete line before and after

I have the following file: line1 line2 MATCH line3 line4 I need to find the pattern, "MATCH" and delete the line before and after MATCH. So the result should be line1 MATCH lline4 I have to use sed because it is the only utility that is common across my environments. I... (1 Reply)
Discussion started by: craftereric
1 Replies

8. Shell Programming and Scripting

sed find matching pattern delete next line

trying to use sed in finding a matching pattern in a file then deleting the next line only .. pattern --> <ad-content> I tried this but it results are not what I wish sed '/<ad-content>/{N;d;}' akv.xml > akv5.xml ex, <Celebrant2First>Mickey</Celebrant2First> <ad-content> Minnie... (2 Replies)
Discussion started by: aveitas
2 Replies

9. Shell Programming and Scripting

sed: find match and delete the line above

I am searching a dhcpd.conf to find the hardware ethernet match, then once the match is found delete just the line above it. For example: testmachine.example { hardware ethernet 00:00:00:00:00:00; fixed address 192.168.1.100; next-server 192.168.1.101; filename "linux-install/pxelinux.0"; }... (3 Replies)
Discussion started by: cstovall
3 Replies

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