• Post Reply Bookmark Topic Watch Topic
  • New Topic

unix / manipulating the content of a file  RSS feed

 
divya madala
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm jsut learning UNIX.
This might be a simple task but for me it's not!!!
I want to delete all those lines from the .dat file where ever it finds a "particular" string.
How to do that in a unix script?
In otherwords, how to keep all those lines which has that string in a file, deleting every other lines that do not have that string?
Thanks,
Divya
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When all's said and done, you have to completely re-write the entire file's new contents. Text files are not really "editable" line-by-line.
 
Bhushan Jawle
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to do this in Unix. Simplest way I can think of is
grep -v 'you pattern' yourFile.dat > yourNewFileWithLinesWOThePattern.dat
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sed '/deletepattern/d' input.txt >output.txt

G.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!