• Post Reply Bookmark Topic Watch Topic
  • New Topic

removing data record  RSS feed

 
michael bradly
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on an assignment and have found myself stuck.
I have a data file with a series of records like:
D4:some name:some id:some email
E45:some name:some id: some email
etc.
The script I am working on accepts input to search for a number in the first field -sans the D or E- to see if it exists, then prompt the user if they want it removed.
I know how to find the record, but I am getting stuck on how to extract that out of the record.
Essentially what I am trying to do is cat the file, pipe it to grep to extract all the files but that one and put them into a temp file that will be renamed to the original later:
cat fileName | grep -E "^[^DE]4:" > $$TEMP
I keep coming up empty with this idea.
Any suggestions would be appreciated.
Regards, Michael
[ November 27, 2002: Message edited by: michael bradly ]
[ November 27, 2002: Message edited by: michael bradly ]
 
Lewin Chan
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Data file called fred for want of a better name.

with script.

gives output

Does this do what you want?. I'm not sure why your pattern match uses two carets. It should match the beginning of a line, which won't occur twice...
brgds
L
[ November 27, 2002: Message edited by: Lewin Chan ]
 
michael bradly
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually that got me exactly what I wanted. I had forgotten about the -v option as a means of negation. But then again, it is late
The ^[^DE] is supposed check for lines not starting with D or E. At least that is what my book says, but I surely couldn't get it to work.
Anyways, thanks for reminding me. I'll try not to forget it again
Regards, Michael

Originally posted by Lewin Chan:
Data file called fred for want of a better name.

with script.

gives output

Does this do what you want?. I'm not sure why your pattern match uses two carets. It should match the beginning of a line, which won't occur twice...
brgds
L
[ November 27, 2002: Message edited by: Lewin Chan ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!