sed magic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed magic
# 1  
Old 06-15-2012
sed magic

Hello all,

I have an inherited an old ugly script I'm trying to clean up a bit.
What I am currently working on is a line like the following:

Code:
Complication=" and ta.secID  = 011222 and upper(ta.proc_ctrl_no) != 'IMPACT'";;

I just want to combine a search for lines that begin with Complication
and then remove the double ";;" at the end of those lines.

There are other case blocks in the script, so I don't want to just remove them from any line. I have tried various combinations using \1 but I seem to keep grabbing the entire line.
Is there a way to say search for lines beginning with ___ AND remove the last two characters? I can do each separately, but I can't figure out how to combine them.

Any hints would be greatly appreciated.

Thanks
# 2  
Old 06-15-2012
Does this do what you'd like?
Code:
sed -e '/Complication=.*;;$/!b'  -e 's/;;$//' input-file >output-file

If the line isn't Complication= with two semicolons at the end, it just prints the line; otherwise it strips the trailing semis.
# 3  
Old 06-16-2012
or:
Code:
sed '/Complication=.*;;$/s/..$//' infile

or
Code:
sed '/\(Complication=.*\);;$/\1/'  infile

# 4  
Old 06-18-2012
@Agama
Unfortunately that did not work.

@Scrutinizer
I had already tried both of those, (Tried yours too just in case), but neither of those work.

I think I may just get rid of any lines ending with a '";;' then I will only have to fix 15 lines. That's not too bad.
# 5  
Old 06-18-2012
Are you certain your input file is not in DOS format?
Do you see \r's when you do:
Code:
head infile | od -c

Otherwise, what is your OS and version?
# 6  
Old 06-18-2012
could u plz try this .....

Code:
sed -n '/^Complication/s/..$//p' input


Last edited by Scrutinizer; 06-18-2012 at 02:19 PM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. What is on Your Mind?

I got a magic wand

My new magic wand just came. It looks great. Looking at it, it looks like it is carved by hand from a solid piece of wood. It could easily serve as a prop in a Harry Potter film. But it is actually a high tech appliance. A built-in accelerometer can detect how you are moving the wand. ... (2 Replies)
Discussion started by: Perderabo
2 Replies

2. Shell Programming and Scripting

sed magic

I want to become an expert @ using sed, but i do not have enough time... Atm I have a repository in my apt/sources.list but it is commented out since i do not want to install packages from it (backtrack repository) except the exploitdb package. I would like make a command, lets say... (5 Replies)
Discussion started by: redsolja
5 Replies

3. UNIX for Dummies Questions & Answers

magic 8ball

when i use this code for the script of the magic 8ball, i get an error message and it always displays the sam answer. What am i doing wrong or what am i missing thanks #!/bin/sh #< Magic eight ball! # KW 26/11/04 # Requires "rand" echo "Enter \"q\" followed by return to quit" function... (6 Replies)
Discussion started by: JamieMurry
6 Replies

4. Shell Programming and Scripting

sed magic!

Hi, I have this line in my script, and works perfect! tran= "$(sed = "$fname" | sed "/./N; s/\n/: /" | sed -n "${beg},${end}p")" $fname its a file, and gets multilines between beg and end.: Something like this: 1: line a 2: line b 3: line c But now, I want insert in the end of each... (9 Replies)
Discussion started by: vibra
9 Replies

5. UNIX for Advanced & Expert Users

magic.h

Where can I find #defines for filetypes like the ELF etc and the magic.h file? CAn anyone advice. Thanks in advance. (1 Reply)
Discussion started by: vijlak
1 Replies

6. UNIX for Dummies Questions & Answers

magic.h

Where can I find #defines for filetypes like the ELF etc and the magic.h file? CAn anyone advice. Thanks in advance. (0 Replies)
Discussion started by: vijlak
0 Replies

7. UNIX for Dummies Questions & Answers

Partion Magic problems.

Hiya people, A great big "HI" to everybody. I'm new to the Forum and now to my problem(s). I am about to partition my only 80GB HD and using the Partition Magic 8 software it looks fairly simple although here is my problem :- 1. Do I change the new partition to primary or logical? 2. Do I... (4 Replies)
Discussion started by: Syndrome_00
4 Replies

8. UNIX for Advanced & Expert Users

what is magic file ?

i am working under this sysytem SunOS sparc SUNW,UltraAX-i2 Some system on this server creates a file named like this. Elem_ee.xml.gz Elem_ee.xml.gz.magic In order to look into Elem_ee.xml.gz.magic, i first renamed Elem_ee.xml.gz.magic to Elem_ee.xml.gz and tried to unzip it. but returns... (3 Replies)
Discussion started by: oppai
3 Replies

9. UNIX for Dummies Questions & Answers

Boot Magic 7

For a multi-boot setup (win2K, XP & SuSE) over 3 drives, where should Boot Magic be installed to? And does it matter which o/s installs it? (3 Replies)
Discussion started by: onestepto
3 Replies
Login or Register to Ask a Question