LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to remove lines with variable value (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-remove-lines-with-variable-value-892700/)

mashinde 07-20-2011 05:57 AM

how to remove lines with variable value
 
Hi frds,

I have model output data in ascii format. It contains thousands of lines. The output file contains multiple text lines with variable values. here I copy-paste some of it's contents.


Code:

  73438  170 23:53:20  3.481328E-03  1.824611E+04  1.824612E+04  1.333962E+16
  73439  170 23:56:40  3.481210E-03  1.824611E+04  1.824612E+04  1.333962E+16
  73440  171 00:00:00  3.481093E-03  1.824611E+04  1.824612E+04  1.333962E+16
      DEF_HIS  - creating history file: /share/scratch/odc/mahesh/roms_files/output/rmed16_grd_e/GLS/his_rmed16_grd_gls_0171.nc
      WRT_HIS  - wrote history  fields (Index=1,1) into time record = 0000001
      DEF_DIAGS - creating diagnostics file: /share/scratch/odc/mahesh/roms_files/output/rmed16_grd_e/GLS/dia_rmed16_grd_gls_0170.nc
      WRT_DIAGS - wrote diagnostics fields into time record =          0000001
      WRT_RST  - wrote re-start fields (Index=1,1) into time record = 0000002
  73441  171 00:03:20  3.480976E-03  1.824611E+04  1.824612E+04  1.333962E+16
  73442  171 00:06:40  3.480859E-03  1.824611E+04  1.824612E+04  1.333962E+16
  73443  171 00:10:00  3.480742E-03  1.824611E+04  1.824612E+04  1.333962E+16
..
..
..
..
..
..
..

  73871  171 23:56:40  3.435554E-03  1.824611E+04  1.824611E+04  1.333962E+16
  73872  172 00:00:00  3.435464E-03  1.824611E+04  1.824611E+04  1.333962E+16
      DEF_HIS  - creating history file: /share/scratch/odc/mahesh/roms_files/output/rmed16_grd_e/GLS/his_rmed16_grd_gls_0172.nc
      WRT_HIS  - wrote history  fields (Index=1,1) into time record = 0000001
      DEF_DIAGS - creating diagnostics file: /share/scratch/odc/mahesh/roms_files/output/rmed16_grd_e/GLS/dia_rmed16_grd_gls_0171.nc
      WRT_DIAGS - wrote diagnostics fields into time record =          0000001
      WRT_RST  - wrote re-start fields (Index=1,1) into time record = 0000002
  73873  172 00:03:20  3.435374E-03  1.824611E+04  1.824611E+04  1.333962E+16
  73874  172 00:06:40  3.435284E-03  1.824611E+04  1.824611E+04  1.333962E+16


and so on


i want to remove the lines starting by WRT and DEF.
so how can do it..please help.

Thanking you

Mahesh

colucix 07-20-2011 06:11 AM

Welcome to LinuxQuestions! Are you running ROMS? ;)
Code:

sed -r '/^DEF|^WRT/d' file
Add option -i if you want to edit the file in place, otherwise redirect standard output to a new file.

mashinde 07-20-2011 06:23 AM

Thanks for the reply. Yes I am running ROMS model.

mahesh

zentara 07-20-2011 06:25 AM

If you have Perl installed

#!/usr/bin/perl
use warnings;

open ( IH, '<', './path_to _your_file') or die "$!\n";
open ( OH, '>', './your_output_filename') or die "$!\n";

while (<IH>) {
next if /^DEF/;
next if /^WRT/;
print OH;
}
__END__

mashinde 07-20-2011 08:03 AM

Quote:

Originally Posted by mashinde (Post 4420004)
Thanks for the reply. Yes I am running ROMS model.

mahesh

No it's not working......................

colucix 07-20-2011 08:27 AM

Quote:

Originally Posted by mashinde (Post 4420070)
No it's not working......................

What is not working? And what is not working means? Actually in the ROMS log the DEF_ and WRT_ keywords are not written at the beginning of the line, hence the sed command should be simply:
Code:

sed -r '/DEF_|WRT_/d' roms.log
without the ^ anchor that identifies the beginning of the line.

PS: I've edited your post adding CODE tags to preserve the spacing of the original text, so that it's more evident where the problem comes from.

grail 07-20-2011 08:36 AM

Not being familiar with ROMS logs, are we sure that DEF_ and WRT_ won't appear anywhere else in the line?
If they might you can cover white space with:
Code:

sed -r '/^[[:space:]]*(DEF_|WRT_)/d' roms.log

colucix 07-20-2011 08:59 AM

Quote:

Originally Posted by grail (Post 4420109)
Not being familiar with ROMS logs, are we sure that DEF_ and WRT_ won't appear anywhere else in the line?

Yes! :) Anyway, your improvement is absolutely correct! :jawa:


All times are GMT -5. The time now is 10:27 AM.