sed not applying /d "delete line" option


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed not applying /d "delete line" option
# 1  
Old 03-10-2017
sed not applying /d "delete line" option

So I'm on an AIX machine.

And sed is not applying /d "delete line" option when I also include match word options \< and \>

examples...
Code:
echo cat | sed '/\<cat\>/d'

will return cat for some reason

Code:
echo cat | sed "/\<cat\>/d"

will also still return cat.

Of course i can just run
Code:
echo cat | sed '/cat/d'

nothing returned as the /d 'delete line' option is now is applied.
But I need to match the word exactly.... so what am I doing wrong?


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-10-2017 at 10:55 AM.. Reason: Added CODE tags.
# 2  
Old 03-10-2017
As both your examples work on my linux host, but not on FreeBSD, I presume it's your sed version that doesn't like the word delimiters.
# 3  
Old 03-10-2017
Sorry, I was not meaning to double post, I though it would be better to have thread in 'Shell Programming and Scripting ' then here, "programming" So I was going to delete this thread.
Thanks for the reply. still tying to figure out a work around here.
# 4  
Old 03-10-2017
Hi,

This is certainly a messier and less efficient solution, but in the absence of word boundaries in your sed implementation you could maybe do something like this ?

sed -e "/^cat /d" -e "/ cat$/d" -e "/ cat /d"

So specifically checking for lines starting with 'cat' and then a space; lines ending with a space and then 'cat'; and lastly lines containing 'cat' surrounded by a space on either side. And so on in that fashion, if there are any other cases that would occur in your input (you'd have to consider punctuation marks, etc).

As I say, messy, but you could cobble something together in this way maybe.
# 5  
Old 03-10-2017
Moved thread to desired forum.


Adaption of drysdalk's proposal:
Code:
echo "as cat, " | sed -r '/(^|[[:punct:][:space:]])cat([[:punct:][:space:]]|$)/d'

or

Code:
echo "cat, " | sed -r '/(^|[^[:alnum:]])cat([^[:alnum:]]|$)/d'


Last edited by RudiC; 03-10-2017 at 01:10 PM..
# 6  
Old 03-10-2017
Thanks for the replies drysdalk and rudic.

drysdalk - I was able to achieve what I wanted from the example of your code!, thanks!
Code:
 sed -e "/^cat /d" -e "/ cat$/d" -e "/ cat /d"


rudic - Sadly the -r option isn't available for sed in AIX, I wasn't able to get your examples to work.
# 7  
Old 03-10-2017
Is the -E option available instead - both have the meaning "use extended regexes"?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

2. Shell Programming and Scripting

Find "*.c" and "Makefile" and then delete them with one line

find "*.c" and "Makefile" and then delete them with one line (3 Replies)
Discussion started by: yanglei_fage
3 Replies

3. Shell Programming and Scripting

Is it possible to use sed to handle the line contains BOTH "AA" and "BB"

if yes, can some expert give an example Lei (2 Replies)
Discussion started by: yanglei_fage
2 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Delete files older than "x" if directory size is greater than "y"

I wrote a script to delete files which are older than "x" days, if the size of the directory is greater than "y" #!/bin/bash du -hs $1 while read SIZE ENTRY do if ; then find $1 -mtime +$2 -exec rm -f {} \; echo "Files older than $2 days deleted" else echo "free Space available"... (4 Replies)
Discussion started by: JamesCarter
4 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

9. Shell Programming and Scripting

cat/delete per line any word "192.168.1.12"

Hi All Can u help me.. My problem is delete word per line sample: cat /tmp/file.txt monitor 192.168.1.11 Copying files in current directory 1 monitor 192.168.1.1 Copying files in current directory 2 monitor 192.168.1.12 Copying files in current directory 3 monitor 192.168.1.14... (1 Reply)
Discussion started by: carnegiex
1 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question