Do not find the mistake in a small routine!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Do not find the mistake in a small routine!!!
# 1  
Old 04-15-2011
Do not find the mistake in a small routine!!!

Have a textfile (regular updated) with informations about datafiles .
Each line is describing a datafile. Now I am trying to delete several specific lines in this textfile, which are defined before in a kind of removal list.
Can not find the mistake I have done in the script because in the updated list the entries are still there.
Code:
remove_list='_12345_ _54321_ _2468_ _abcde_'
for delete in `echo remove_list`
   do   
     sed -e "/$delete/d" old_list > updated_list
   done

Can anybody please help me where I made the mistake?


Jurgen
# 2  
Old 04-15-2011
Quote:
Originally Posted by jurgen
remove_list='_12345_ _54321_ _2468_ _abcde_'
for delete in `echo remove_list`
do
sed -e "/$delete/d" old_list > updated_list
done
remove_list is a file or a variable..? If its a file use cat instead of echo else if its a variable use $ sign before the name.
Code:
for delete in `echo $remove_list`

# 3  
Old 04-15-2011
useless use of echo. You can do without. Bigger problem is in the redirection. You are overwriting your updated_list at every run of sed.
Use in-place editing instead:
Code:
remoremove_list='_12345_ _54321_ _2468_ _abcde_'
cp old_list updated_list
for delete in $remove_list ;  do   
     sed -i "/$delete/d" updated_list
   done

# 4  
Old 04-15-2011
the remove list are variables.For example:
remove_list='_12345_ '
- this line should be removed in the old_list.txt
home/user/..../20110414/XXX_12345_20110414.txt,50.4......


Regards
Jurgen

---------- Post updated at 04:26 AM ---------- Previous update was at 04:15 AM ----------

Quote:
Originally Posted by mirni
useless use of echo. You can do without. Bigger problem is in the redirection. You are overwriting your updated_list at every run of sed.
Use in-place editing instead:
Code:
remoremove_list='_12345_ _54321_ _2468_ _abcde_'
cp old_list updated_list
for delete in $remove_list ;  do   
     sed -i "/$delete/d" updated_list
   done

Its working if I use "sed -e" instead of "sed -i"
One additional question...how can I use also the remove list to delete the corresponding files...
Something like that

Code:
cd $directory
for i in HLF_TF_*.txt
do 
   rm $remove_list
done

THANKS VERY MUCH FOR THE HELP

Last edited by jurgen; 04-15-2011 at 06:38 AM..
# 5  
Old 04-15-2011
If you use -e only, it is going to print the output on stdout, but will not change updated_list. If you use '-e -i', it's gonna do editing-in-place and print nothing to the screen, bot modify the updated_list file.

Quote:
One additional question...how can I use also the remove list to delete the corresponding files...
I'm not sure what you mean here... What are the corresponding files?
If you want to remove any files that contain any string in your list, then like this:

Code:
cd $dir
for r in $remove_list ; do 
  echo rm *${r}*  #remove echo when you sure you want to delete
done

This User Gave Thanks to mirni For This Post:
# 6  
Old 04-15-2011
Thats what I wanted to do,

Thank you very much for the help Smilie

Jurgen
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find words containing small letters

Hello, I have a file containing different words. How can i print the words which contain at least one small letter, for example if i have: today TOMORROw 12345 123a next preViou5 no it should print the following: today TOMORROw 123a next preViou5 no Please use code tags as required... (5 Replies)
Discussion started by: JhonTheNewbie
5 Replies

2. Shell Programming and Scripting

Can anyone find the mistake in this script file

#!/bin/ksh db_user=`echo $DB_USER_NAME` db_pwd=`echo $DB_PASSWORD` db_sid=`echo $TWO_TASK` sqlplus -s $db_user/$db_pwd@$db_sid << EOF a = select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and bus_event_seq_nbr='3969094' set -- echo $a |... (17 Replies)
Discussion started by: rkrish
17 Replies

3. UNIX for Dummies Questions & Answers

Probably some stupid mistake...

Hi everyone ! I have a file wich look like this : >Sis01 > Sis02 ... >Sis44 I want to separe each paragraphe in a different file, so I decide to use the "FOR" loop + sed. for f in {01..44} do (5 Replies)
Discussion started by: sluvah
5 Replies

4. Shell Programming and Scripting

Is there any mistake in this code:

cat $1 | sort -n | uniq | $1 in other words, I sort the content of the file and put the ouput in the same file, is there any mistakes in this cshell code ??? (4 Replies)
Discussion started by: Takeeshe
4 Replies

5. Shell Programming and Scripting

awk routine help

Hi, I use awk but not as a programming language. Just generally in piplelines to split things out by fields. I am trying to accomplish this one thing that I think a short awk routine would do great for, but can't figure it out. Lets say I have a file that contains database columns. The file... (25 Replies)
Discussion started by: fwellers
25 Replies

6. Shell Programming and Scripting

Can't find the mistake in sed expression

Hi there, Can anyone help me find the correct expression for sed. I want to repace iface eth0 inet wathever with iface eth0 inet static Thanks for your help Santiago (5 Replies)
Discussion started by: chebarbudo
5 Replies

7. AIX

Did a Mistake with HACMP

Hi, I needed space on a FS, and when I've added the space on the filesystem, I did it trough the regular smitty fs inteface and not with smitty cl_lvm. Can someone help me to repair the situat before a faileover happen ? Thanks for your help,:mad: (13 Replies)
Discussion started by: azzed27
13 Replies

8. Shell Programming and Scripting

sub routine call

in windows machine... C:\2\test>perl -version This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) ------------------------------------------ what is the difference b\w subroutine calls: sub_routine_name("-----"); and ... (2 Replies)
Discussion started by: sekar sundaram
2 Replies

9. UNIX for Dummies Questions & Answers

Crontab Mistake!!!

Hi. I hope someone can help me with this problem. Being a novice to Unix, I editted my crontab directly by typing " crontab -e ". Well, I needed to make some changes so, I typed " crontab -r ". Now I have no crontab, and I can't seem to get crontab to write a new file. I' ve tried: vi... (4 Replies)
Discussion started by: cstovall
4 Replies

10. UNIX for Dummies Questions & Answers

Directory find in small and capitals

I've a very trivial thing bothering me. I'm rather new in scripting so I'll keep asking stupid questions. Here is small script that does backup of mails. --- for i in `cat /maildir.dir` do echo $i maildir=`echo $i|sed 's@^./usr/@@'` for j in $i/* do && { st="`find $j/backup -name "*"... (3 Replies)
Discussion started by: nitin
3 Replies
Login or Register to Ask a Question