LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 06: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 09:28 AM.
 
Old 07-20-2011, 07:11 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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, 07: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, 07:25 AM   #4
zentara
LQ Newbie
 
Registered: Jul 2011
Posts: 2

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, 09: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, 09:27 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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 09:29 AM.
 
Old 07-20-2011, 09:36 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

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

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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-04-2010 12:09 AM
Using variable to store command lines in a pipeline? zizou86 Programming 6 01-29-2010 11:20 AM
[SOLVED] Setting System Variable LINES ashok.g Programming 1 12-03-2009 08:15 AM
How to remove lines and parts of lines from python strings? golmschenk Programming 3 11-27-2009 12:29 AM
have a Variable with multiple lines of data need to have it all on one line seperated xskycamefalling Programming 11 05-12-2009 05:44 AM


All times are GMT -5. The time now is 10:03 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration