Sponsored Content
Top Forums Shell Programming and Scripting Remove a block of Text at regular intervals Post 302468363 by ctsgnb on Tuesday 2nd of November 2010 01:25:55 PM
Old 11-02-2010
By setting "Frame" as record separator , i must get rid off the leading line "^14$", i must adjust the offset of record, this is why the NR-1 instead of NR

Code:
awk -F"\n" 'BEGIN {RS="Frame" ;ORS="Frame";printf "%s","Frame"} ; ((NR-1)%2!=0)&&((NR-1)%3!=0)' infile

or
Code:
awk -F"\n" -vRS="Frame" -vORS="Frame" 'BEGIN{printf "%s",RS};((NR-1)%2!=0)&&((NR-1)%3!=0)' infile

Code:
# cat infile
14
Frame 1
Ir 0.4482 -1.2980 -0.2902
H -0.8380 -0.5636 2.1141
...
H -1.0869 -0.4380 2.8141
14
Frame 2
Ir 0.4490 -1.2978 -0.2903
P 1.8738 -2.1613 1.4076
...
H -1.2309 -0.4996 2.7795
14
Frame 3
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
P -1.4956 -0.6824 -1.5757
H -2.5240 0.2145 -1.1716
14
Frame 4
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
P -1.4956 -0.6824 -1.5757
H -2.5240 0.2145 -1.1716
14
Frame 5
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
P -1.4956 -0.6824 -1.5757
H -2.5240 0.2145 -1.1716
14
Frame 6
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
P -1.4956 -0.6824 -1.5757
H -2.5240 0.2145 -1.1716
14
Frame 7
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
14
Frame 8
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
14
Frame 9
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
14
Frame 10
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
14
Frame 11
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
.
.
.
14
Frame 72
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
P -1.4956 -0.6824 -1.5757
H -2.5240 0.2145 -1.1716
H -2.2321 -1.8577 -1.8841
H -1.2106 -0.1808 -2.8791
H 2.8807 -2.5381 1.3446
H 0.9971 -3.2308 2.2364
H 1.8734 -1.3013 2.8541
C 1.7346 -0.5673 -1.1992
O 2.6174 -0.1436 -1.8621
Cl 0.2051 -3.5805 -0.9057
H 0.1695 0.2982 0.6158
H -0.9713 -1.5095 0.9427
# awk -F"\n" -vRS="Frame" -vORS="Frame" 'BEGIN{printf "%s",RS};((NR-1)%2!=0)&&((NR-1)%3!=0)' infile
Frame 1
Ir 0.4482 -1.2980 -0.2902
H -0.8380 -0.5636 2.1141
...
H -1.0869 -0.4380 2.8141
14
Frame 5
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
P -1.4956 -0.6824 -1.5757
H -2.5240 0.2145 -1.1716
14
Frame 7
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
14
Frame 11
Ir 0.2799 -1.1423 -0.0744
P 1.5830 -2.0634 1.6851
.
.
.
14
#


Last edited by ctsgnb; 11-02-2010 at 02:43 PM..
This User Gave Thanks to ctsgnb For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

mailing myself at regular intervals...

hi all, i wrote a script to mail myself using pine (modified) to keep remind of b'days. #!/bin/bash grep "`date +%D |awk -F/ '{print $2+1, $1+0}'`" dataFile >/home/username/mailme if test -s /home/username/mailme then pine -I '^X,y' -subject "Birthday Remainder" username... (4 Replies)
Discussion started by: timepassman
4 Replies

2. Programming

performing a task at regular intervals

hi! i m tryin to write a program that will perform a specific tasks after fixed interval of time.say every 1 min. i jus donno how to go abt it.. which functions to use and so on... i wud like to add that i am dont want to use crontab over here. ny lead is appreciated. thanx. (2 Replies)
Discussion started by: mridula
2 Replies

3. Shell Programming and Scripting

Pls Help me out ... I want to check process status at regular intervals of time

I want to check process status at regular interval of time ... so i ha wirtten this BUT its not working when i placed this peace of code in .sh .. please help me out #!/bin/sh w = ps -ef|grep processname | wc - l echo $w if ; then Banner "Proceesname Problem" else Banner " Running... (5 Replies)
Discussion started by: srinivasvandana
5 Replies

4. Shell Programming and Scripting

Grouping data numbers in a text file into prescribed intervals and count

I have a text file that contains numbers (listed from the smallest to the largest). For ex. 34 817 1145 1645 1759 1761 3368 3529 4311 4681 5187 5193 5199 5417 5682 . . (5 Replies)
Discussion started by: Lucky Ali
5 Replies

5. Shell Programming and Scripting

Need perl regular expression to remove the comment

I need a perl substitution to remove only the comment in the line . That line may have '#' with in double quotes .I used the following , s/(^.*\".+?#.+?\".+?)(#.*)/$1/g It works for , print " not a comment # not a comment " . "not a comment # not a comment" ; # It is a comment ... (3 Replies)
Discussion started by: karthigayan
3 Replies

6. UNIX for Advanced & Expert Users

awk - remove block of text, multiple actions for 'if', inline edit

I'm having a couple of issues. I'm trying to edit a nagios config and remove a host definition if a certain "host_name" is found. My thought is I would find host definition block containing the host_name I'm looking for and output the line numbers for the first and last lines. Using set, I will... (9 Replies)
Discussion started by: mglenney
9 Replies

7. Shell Programming and Scripting

Filter or remove duplicate block of text without distinguishing marks or fields

Hello, Although I have found similar questions, I could not find advice that could help with our problem. The issue: We have several hundreds text files containing repeated blocks of text (I guess back at the time they were prepared like that to optmize printing). The block of texts... (13 Replies)
Discussion started by: samask
13 Replies

8. Programming

Selecting files in regular intervals from a folder

Hi, I need your expertise in selecting files from a folder. I have files named with convention: filename.i.j where j is an interger from 1 to 16, for each i which is an integer from 1 to 2000. I would like to select the files with i in regular interval of 50 like filename.1.j,... (2 Replies)
Discussion started by: rpd25
2 Replies

9. Shell Programming and Scripting

perl regular expression to remove the special characters

I had a string in perl script as below. Tue Augáá7 03:54:12 2012 Now I need to replace the special character with space. After removing the special chaacters Tue Aug 7 03:54:12 2012 Could anyone please help me here for writing the regular expression? Thanks in advance.. Regards, GS (1 Reply)
Discussion started by: giridhar276
1 Replies

10. UNIX for Dummies Questions & Answers

Bulk load testing in regular intervals

I need to write a script which can send files via sftp communication continously for half an hour or any given duration of time. I have already written a batch file to send multiple file via SFTP. but I need to know how can we set a duration of half an hour through shell script. Can we use sleep... (2 Replies)
Discussion started by: talk1234
2 Replies
All times are GMT -4. The time now is 01:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy