Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing spetsific lines in file 1

Status
Not open for further replies.

enni

Technical User
Oct 30, 2003
5
EE
I am stuck on a problem of deleting input lines from a file.
The first 9 char indicating a file name and this line should be removed and rest of lines should be send to outpile. In below you can find my first script, but unfortunately it will removing only last line in file eg "CDALLLLLS01148"

input file(list.txt):
CDALLLLLS01147
CDALLLLLS01148
CDARRRRRR01150
CDARRRRRR01151
CDARRRRRR01152

script:

#!/bin/sh
list=uus.txt

while read line
do
file="`echo $line|cut -c 1-8`"
less $file | sed -e "/^$line/!d" >$file.new

done < $list

thanks for you help
 
Try to replace this line:
Code:
less $file | sed -e &quot;/^$line/!d&quot; >$file.new
by this snippet:
Code:
[ -f $file.new ] && inp=$file.new || inp=$file
sed -e &quot;/^$line/d&quot; $inp >$file.tmp
mv $file.tmp $file.new

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top