Delete lines ending in "_;" using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete lines ending in "_;" using sed
# 8  
Old 01-02-2007
I could use some more help on the same topic. Now I need to use sed to delete the portion of the line in parenthesis if the line begins with CHAR. Thanks everyone.

This is the command I'm playing with:

Code:
sed -e '/CHAR/!s/([A-Z0-9]*//g'

BASE DESCRIPTION (BSEDS)
This would become this
BASE DESCRIPTION

This would not change
CHAR BASE DESCRIPTION (BSEDS)
# 9  
Old 01-03-2007
Turbulence,

If you want to delete the portion of the line in parenthesis if the line begins with CHAR, you can try this:
Code:
echo "CHAR BASE DESCRIPTION (BSEDS)" | sed 's/^(CHAR.*\)(.*)/\1/'

Quote:
Originally Posted by Vino
sed -n -e "s/^\(.*\) \([^_]*;\)$/\1 c\2/p"
Above will omit line if there is "_" anywhere in the line, it doesn't look specifically for the '_;' at the end of line, e.g.
Code:
(string \\;\) cba_se
(string \\;\) bse;
(string \\;\) cflavor_;
(string \\;\) flv;

Output:
Code:
(string \\;\) cbse;
(string \\;\) cflv;

Regards,
Tayyab
# 10  
Old 01-03-2007
Thank you for your help but your command is giving me an error.

Code:
echo "CHAR BASE DESCRIPTION (BSEDS)" | sed 's/^\(CHAR.*\)(.*)/\1/'
sed: -e expression #1, char 21: Unmatched ) or \)

I tried adding slashes and parens in several places but it still wouldn't work.

Edit: I got it to work but it's doing the opposite of what I need. I need it to *not* delete from lines starting with CHAR.

CHAR BASE DESCRIPTION (BSEDS)
this would stay the same.

BASE DESCRIPTION (BSEDS)
would become
BASE DESCRIPTION

Last edited by turbulence; 01-03-2007 at 11:35 AM..
# 11  
Old 01-03-2007
I found the solution. Here it is in case anyone wants to use it in the future.

Code:
sed -e '/CHAR/ !s/^\(.*\) (.*)/\1/'

# 12  
Old 01-17-2008
Hi, I am trying do the same as above but I want to delete all lines that do not start with a '-' negative sign...so i tried the above command by replacing CHAR with - ....but did not work...any other suggestions?
# 13  
Old 01-17-2008
Code:
sed '/^[^-]/d'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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... echo cat | sed '/\<cat\>/d'will return cat for some reason echo cat | sed "/\<cat\>/d"will also still return cat. Of course i can just run echo cat... (9 Replies)
Discussion started by: escooter87
9 Replies

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

3. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

4. Shell Programming and Scripting

Find out if multiple files have lines ending with"r"

I am trying to find out which files in a group of files have lines ending in r. What I have is this: cat /tmp/*RECORDS| if grep r$>/dev/null; then echo "yes";else echo"no";fi Records is more than one file. There are the following files TEST-RECORDS /volume/testing /volume/programs ... (2 Replies)
Discussion started by: newbie2010
2 Replies

5. Shell Programming and Scripting

Delete till ">" is found in all lines in a file

Hi, I have a file which has lines like these : I want to trim everything from the left till ">" such that the file looks like : If you have any ideas how to do this in 1-2 commands please help. Thanks. (3 Replies)
Discussion started by: sinpeak
3 Replies

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

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

8. Shell Programming and Scripting

Sed: Delete lines in files that contain other than a-z ,0-9 and "."

Sed: Delete lines in files that contain other than 'a-z' ,'0-9', '.' and '-' Hello, I'm looking for a shell command or maybe a small php loop to delete lines in files.txt (in the same directory) that contain character other then 'a-z' ,'0-9', '.' and '-' All line that have characters like... (4 Replies)
Discussion started by: devlin
4 Replies

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

10. UNIX for Dummies Questions & Answers

get two strings ending with "." and starting with "."

Hi all, In unix shell, I want to get two strings ending with "." and starting with "." from a string "chan.txt" For example, a string "chan.txt". The first string is "chan" The second string is "txt" Yours Wilson (1 Reply)
Discussion started by: wilsonchan1000
1 Replies
Login or Register to Ask a Question