• Post Reply Bookmark Topic Watch Topic
  • New Topic

delete row in linux file based on condition  RSS feed

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

If my input file has below data,I want to delete those rows only in which last column has 2 digits after decimal point. how to write command for this ?

111111|113|MP201205211619451202912|2012-01-12+05:30|2012-01-24+05:30|1255.04
222222|117|OR201205281857441108388|2012-01-05+05:30|2012-01-18+05:30|944.8


Thanks,
Joy
 
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'cat' the flle and pipe into 'grep' using a regex to select the rows of interest. Direct the result to a new file. I normally use the -P regex option for this sort of filtering.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use wild cards (*,?) for this
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
smitha menon wrote:you can use wild cards (*,?) for this


Could you elaborate because I don't see what you are getting at.
 
Saloon Keeper
Posts: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Tookey wrote:'cat' the flle and pipe into 'grep' using a regex to select the rows of interest. Direct the result to a new file. I normally use the -P regex option for this sort of filtering.


The grep command can do its own "cat"ing. Somnething like:


Expect grief. I always have problems with character escapes on the command line. Never can get the backslash count right.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!