Sponsored Content
Top Forums Shell Programming and Scripting take a section of a data with conditions Post 302691829 by Don Cragun on Sunday 26th of August 2012 01:05:58 AM
Old 08-26-2012
agama said he found a # by itself on a line as the section separator. When I copied the sample input and fed it through od -cb, I found that the separator line contained the octal byte values 343, 200, and 200 terminated by the <newline> character.

I believe the following meets the criteria specified, but nothing will be printed given the sample input because no section header in the sample input has $12 > 3.
Code:
awk 'BEGIN {line1 = 1} # Next line with no alpha-numeric is a section header.
!/[0-9a-zA-Z]/ { # Found what is assumed to be a blank line.
        # The sample input had three bytes with octal values 343, 200, and 200
        #   followed by a <newline> as the separator between sections.
        #   The submitter described this as a "blank line".
        # This script will use empty lines as section separators no matter what
        #   section separator lines are found in input files.
        copy = 0 # Turn off copy mode.
        line1 = 1 # The next non-"blank" line is a sectoin header.
        next
}
copy    {print;next} # Copy any lines found before the next "blank" line.
line1   {if(($1 ~ /^2011/) && ($12 > 3)) { 
                # The text in the first post in this thread said sections were
                #   to be printed only for the year 2011 and $12 is > 3.
                # The script in the first post was looking for years 2010-2019.
                # All entries in the sample input were for 2011, but no entries
                #   had $12 > 3 (the only entries had $12 set to 2.1 and 1.7,
                #   so no entries match the criteria.
                copy=1 # Turn on copy mode for the rest of the section.
                # Add an empty line as a section separator, except before the 1st
                #   section to be printed.
                if(found++ > 0) print ""
                print # Print the 1st line of the section.
        } 
        # Whether a match was found or not, don't look for another seciion
        #   header until we find another separator line.
        line1 = 0
}' input

These 2 Users Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

parsing data for certain conditions

Hi guys, I have got this working OK but I am sure there is a more efficient/elegant way of doing it, which I hope you can help me with. It can be done in whatever is most suitable i.e perl/awk.. Any suggestions are welcome and many thanks in advance. What I require is to extract... (5 Replies)
Discussion started by: PAW
5 Replies

2. Shell Programming and Scripting

Search and Remove No data Section

Hello, I have written a script that removes duplicates within a file and places them in another report. File: ABC1 012345 header ABC2 7890-000 ABC3 012345 Content Header ABC5 593.0000 587.4800 ABC5 593.5000 587.6580 ABC5 593.5000 587.6580 ABC1 67890 header ABC2 1234-0001 ABC3... (2 Replies)
Discussion started by: petersf
2 Replies

3. Shell Programming and Scripting

Organization data based on two conditions applied problem asking...

Input file: HS04636 type header 836 7001 ID=g1 HS04636 type status 836 1017 Parent=g1.t1 HS04636 type location 966 1017 ID=g1.t1.cds;Parent=g1.t1 HS04636 type location 1818 1934 ID=g1.t1.cds;Parent=g1.t1 HS04636 type status 1818... (8 Replies)
Discussion started by: patrick87
8 Replies

4. Shell Programming and Scripting

Extract section of file based on word in section

I have a list of Servers in no particular order as follows: virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection). 9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
Discussion started by: jelloir
2 Replies

5. Shell Programming and Scripting

Prepend first line of section to each line until the next section header

I have searched in a variety of ways in a variety of places but have come up empty. I would like to prepend a portion of a section header to each following line until the next section header. I have been using sed for most things up until now but I'd go for a solution in just about anything--... (7 Replies)
Discussion started by: pagrus
7 Replies

6. Shell Programming and Scripting

split continues lines to separated section with conditions

Hello; i have a file contains N continues records. i want to split these lines to some separate sections with each lines of a section has the desired condition compared to other sections input: AZR ? ? ? Pn 37.202 48.82 1136119044 1136119009 SHB ? ? ? Pn 37.802 48.02 1136119047 1136119008... (4 Replies)
Discussion started by: saeed.soltani
4 Replies

7. Shell Programming and Scripting

Errors in if conditions with to many OR conditions

Hi ALL I have a script where in i need to check for several values in if conditons but when i execute the script it throws error such as "TOO MANY ARGUMENTS" if then msg="BM VAR Issue :: bmaRequestVAR=$bmaRequestVAR , nltBMVAR=$nltBMVAR , bmaResponseVAR=$bmaResponseVAR ,... (10 Replies)
Discussion started by: nikhil jain
10 Replies

8. Shell Programming and Scripting

Getting last section of data from logfile

Hi, I have a log file from Munin like this:2012/12/04 13:45:31 : Munin-update finished (29.68 sec) 2012/12/04 13:50:01 Opened log file 2012/12/04 13:50:01 : Starting munin-update 2012/12/04 13:50:01 Error occured in under in the configuration. 2012/12/04 13:50:01 Could not parse datafile... (9 Replies)
Discussion started by: Jotne
9 Replies

9. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file based on certain conditions

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (1 Reply)
Discussion started by: Vivekit82
1 Replies

10. UNIX for Beginners Questions & Answers

Grep a section from an UNIX file obtaining only part of the data

Hello, I have a log file that has several sections "BEGIN JOB, End of job" like in the following example: 19/06/12 - 16:00:57 (27787398-449294): BEGIN JOB j1(27787398-449294) JOB1 19/06/12 - 16:00:57 (27787398-449294): DIGIT: 0 number of present logs : 1 19/06/12 - 16:00:57... (4 Replies)
Discussion started by: mvalonso
4 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 06:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy