LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-20-2011, 05:57 AM   #1
mashinde
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Rep: Reputation: Disabled
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

Last edited by colucix; 07-20-2011 at 08:28 AM.
 
Old 07-20-2011, 06:11 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 07-20-2011, 06:23 AM   #3
mashinde
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for the reply. Yes I am running ROMS model.

mahesh
 
Old 07-20-2011, 06:25 AM   #4
zentara
LQ Newbie
 
Registered: Jul 2011
Posts: 24

Rep: Reputation: Disabled
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__
 
Old 07-20-2011, 08:03 AM   #5
mashinde
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by mashinde View Post
Thanks for the reply. Yes I am running ROMS model.

mahesh
No it's not working......................
 
Old 07-20-2011, 08:27 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by mashinde View Post
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.

Last edited by colucix; 07-20-2011 at 08:29 AM.
 
Old 07-20-2011, 08:36 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
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
 
Old 07-20-2011, 08:59 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by grail View Post
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Remove all lines containing 'A,,,,,,' hattori.hanzo Programming 6 11-03-2010 11:09 PM
Using variable to store command lines in a pipeline? zizou86 Programming 6 01-29-2010 10:20 AM
[SOLVED] Setting System Variable LINES ashok.g Programming 1 12-03-2009 07:15 AM
How to remove lines and parts of lines from python strings? golmschenk Programming 3 11-26-2009 11:29 PM
have a Variable with multiple lines of data need to have it all on one line seperated xskycamefalling Programming 11 05-12-2009 04:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration