sed is dead


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed is dead
# 1  
Old 05-26-2011
sed is dead

Hello everybody,
I'm new to bash scripting (and scripting in general) but I'm making decent progress in the hands-on solutions I need...
I've encountered a problem that seemed very simple to me at first, but had me going on for hours. Maybe you can help me.

Say I have an input text file like this...

test2:
SOL 0.031 7
SOL 0.032 8
SOL 0.033 8
SOL 0.034 8
SOL 0.035 9
SOL 0.036 9
SOL 0.037 9
SOL 0.038 10
SOL 0.040 10
SOL 0.041 11
SOL 0.042 11
SOL 0.043 11
I'm writing the coordinate of the second column into an array if the number in column 3 does not appear n times (thrice in my case) in the file.

if I echo out my array I get

0.031
0.038
0.040
I iterate through the array with a simple for loop like so...

Code:
for k in ${MOLARRAY[@]}
do
    sed -i -e '/"$k"/d' test2
done

I am trying to delete the lines that contain the values of my array in the text file test2 with sed. I've tried squeezing multiple ways of writing $k between the brackets but for some reason test2 is never edited.

any ideas?
# 2  
Old 05-26-2011
Nietzsche said that about god, not sed! Smilie

The variable is enclose by singe quotes so it will never be evaluated by the shell and sowith sed will never find a match - so no change to the file:
Code:
for k in ${MOLARRAY[@]}
do
    sed -i -e '/'${k}'/d' test2
done

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 05-26-2011
Thanks a bunch zaxxon
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

showing dead accounts?

Got a quick question. How do you shows dead accounts (false shells) and how do you include a count at the end? (1 Reply)
Discussion started by: JA50
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Dead link in FAQ

Dead link from FAQ, then Technical FAQ: Senior Advisor - https://www.unix.com (Was about to suggest that a O/P read this FAQ). (9 Replies)
Discussion started by: methyl
9 Replies

3. What is on Your Mind?

Usenet is dead

On servers i check there seems to be no news at all. (3 Replies)
Discussion started by: Action
3 Replies

4. Filesystems, Disks and Memory

Dead SCSI drive

I have 2 dead SCSI drives. Can anyone tell me a good way to repair the disks??? Please! (1 Reply)
Discussion started by: disturbe_d
1 Replies

5. Shell Programming and Scripting

what is dead.letter ??

Hi all can you please help me what is dead.letter file ? when it is created ? for the first time i have seen this file getting created in my current directory? I am using SunOs. Any IDEA ?? (2 Replies)
Discussion started by: jambesh
2 Replies

6. Filesystems, Disks and Memory

Dead partition on drive

We are still using solaris 1 with sunos 4.1.4 because nobody here knows Unix. My colleague did a backup (dump) to the wrong place (/dev/sd0h) and we lost this part of the drive. The information is still on tape but we cannot repartition the /dev/sd0h. fsck keeps on about the "wrong SUPER BLOCK"... (2 Replies)
Discussion started by: Tom Bekaert
2 Replies

7. UNIX for Dummies Questions & Answers

Jack Kilby dead at 81

If Edison and Ford were the the greatest inventors and influencers of the turn of the 20th century... then surely Jack Kilby was probably the most influential person of the late 21st century and for time immemorial...on our way of life. A legend dies (7 Replies)
Discussion started by: Kelam_Magnus
7 Replies

8. UNIX for Dummies Questions & Answers

dead.letter

HI, I am pretty new to Unix...but here is 1 serious problem...atleast for me..:-) now..the dead.letter file in /var/tmp has been growin continuously..n i dont know why..I ve even killed the sendmail process..but the dead.letter file keeps on increasin..Can anyone tell me where do I start... (6 Replies)
Discussion started by: unisam
6 Replies

9. Solaris

Dead SUN

My SUN V210 refuses to fully boot up. We had a power outage (ie. someone tripped the cord) and thereafter the Sun will not come up, and the OS is not starting. The LED on the front is not lit. Monitor gets no feed, so I plugged in via the management port. The system comes up to: Trap 3e. and... (7 Replies)
Discussion started by: ireeneek
7 Replies
Login or Register to Ask a Question