Sponsored Content
Top Forums Shell Programming and Scripting Script to perform record format checks Post 302427654 by durden_tyler on Monday 7th of June 2010 11:03:25 AM
Old 06-07-2010
One way to do it with Perl:

Code:
$
$
$ cat -n f1
     1  A|c1|c2|c3|....
     2  B|G1|G2|G3....
     3  C|H1|H2|H3...
     4  A|c4|c5|c6|....
     5  B|G4|G5|G6....
     6  C|H4|H5|H6...
     7  A|c7|c8|c9|....
     8  C|H7|H8|H9...
     9  A|c0|c1|c2|....
    10  B|G7|G8|G9....
    11  B|G0|G1|G2....
    12  B|G3|G4|G5....
    13  C|H0|H1|H2...
$
$
$ ##
$ perl -ne 'push @x, $_;
          if (/^A\|/) {$in = 1; $lnum=$.}
          elsif ($in and /^B\|/) {$count++}
          elsif ($in and /^C\|/) {
            printf("The block at line %4d is %10s =>\n", $lnum, ($count == 0 ? "invalid" : "valid"));
            foreach (@x) {print "\t",$_}
            $count=0; $in=0; @x=();
          }
         ' f1
The block at line    1 is      valid =>
        A|c1|c2|c3|....
        B|G1|G2|G3....
        C|H1|H2|H3...
The block at line    4 is      valid =>
        A|c4|c5|c6|....
        B|G4|G5|G6....
        C|H4|H5|H6...
The block at line    7 is    invalid =>
        A|c7|c8|c9|....
        C|H7|H8|H9...
The block at line    9 is      valid =>
        A|c0|c1|c2|....
        B|G7|G8|G9....
        B|G0|G1|G2....
        B|G3|G4|G5....
        C|H0|H1|H2...
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perform some checks on file using perl

hi i want check for PVCS header in file if its present then check if its in proper format or not i want to do this is in perl on windows. this is what i am doing : 1 . open file 2 . check for "PVCS information" if found then store the line no to $line var. 3 . check for "sccs" header ... (0 Replies)
Discussion started by: zedex
0 Replies

2. Shell Programming and Scripting

to perform checks line by line on a file

Hi, I have a file abc.txt with data like this 1 /test/ 2 /test/file.txt 3 /data/ 4 /data/file1.txt 5 /data/file2.txt I want to take out every path from the file and check if its a directory or file. I am trying it with cut with something like this but it doesnt work ... (7 Replies)
Discussion started by: muaz
7 Replies

3. Shell Programming and Scripting

Shell scripts for record Re format

I have few files from windows which are tab delimited or ‘|' delimited files. I need to convert these files without any delimiter ( so in a way it would become variable length with no delimiter ) Can someone help me with the command in bourne shell scripts., ( I am trying with awk ) Thanks In... (6 Replies)
Discussion started by: Shanks
6 Replies

4. Shell Programming and Scripting

[Bash] MD5 Checks with Script.

Hi. I'm triyng to make a Bash Script that checks (recursively) the MD5 from all the files in a certain directory and compare them against some other check that should be already done and saved in a file. I've reached to the point where i have the MD5 from the file and the MD5 that the script... (1 Reply)
Discussion started by: BiFo
1 Replies

5. Shell Programming and Scripting

counting particular record format in a file using AWK

I am trying to count records of particular format from a file and assign it to a variable. I tried below command br_count=wc -l "inputfile.dat"| awk -F"|" '{if (NF != "14") print }' but I amnot able to get it done. Please share me some idea how to get it done. Thanks in advance (7 Replies)
Discussion started by: siteregsam
7 Replies

6. Shell Programming and Scripting

Script to performs checks

Hi , I need a script which performs below activity I have one file named "testfile" in 9 different directories with same name. I want to perform below action with each testfile of each directory. if ; then mv listfiles listfiles_`date +%b%y` else echo No Such files fi ... (4 Replies)
Discussion started by: sv0081493
4 Replies

7. Shell Programming and Scripting

Script to do the following checks

Hi , I need a script for processing below scenario. I have to check daily by doing ftp IP to check it is logging or not. So i want this activity to be automated such that if login succesful i will get "FTP LOGIN SUCCESS" in a log file and if fails i want the error message in the same log... (1 Reply)
Discussion started by: sv0081493
1 Replies

8. Shell Programming and Scripting

Script function which checks if itself is already running

Hi All, I have a cron job set up which is set to run every 10 seconds. What I need to do is have the script do a check to see if it is already running such that if it is running it wont fire up additional instances and processes according to its normal process. For example if I have a script... (4 Replies)
Discussion started by: landossa
4 Replies

9. UNIX for Dummies Questions & Answers

Help! needed to displaying an output in record format

Hi Friends, Am new to Unix world and this is my first post in this forum. I was stuck in displaying the content. while displaying the content the below points to be taken care 1 ) The header format is repeating 2) To display the value in table format... (2 Replies)
Discussion started by: rocky2013
2 Replies

10. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies
Text::WikiFormat::Blocks(3pm)				User Contributed Perl Documentation			     Text::WikiFormat::Blocks(3pm)

NAME
Text::WikiFormat::Blocks - blocktypes for Text::WikiFormat SYNOPSIS
None. Use Text::WikiFormat as the public interface, unless you want to create your own block type. DESCRIPTION
This module merely creates subclasses of Text::WikiFormat::Block, which is the interesting code. A block is a collection of related lines, such as a code block (text to display verbatim in a monospaced font), a header, an unordered list, an ordered list, and a paragraph (text to display in a proportional font). Every block extends "Text::WikiFormat::Block". METHODS
The following methods exist: o "new( %args )" Creates and returns a new block. The valid arguments are: o "text" The text of the line found in the block. o "args" The arguments captured by the block-identifying regular expression. o "level" The level of indentation for the block (usually only useful for list blocks). o "tags" The tags in effect for the current type of wiki formatting. o "opts" The options in effect for the current type of wiki formatting. Use the accessors of the same names to retrieve the values of the attributes. o "add_text( @lines_of_text )" Adds a list of lines of text to the current text for the block. This is very useful when you encounter a block and want to merge it with the previous block of the same type o "add_args( @arguments )" Adds further arguments to the block; useful when merging blocks. o "formatted_text()" Returns text formatted appropriately for this block. Blocks don't have to have formatters, but they may. o "formatter( $line_of_text )" Formats the $line using "Text::WikiFormat::format_line()". You can add your own formatter here; this is worth overriding. o "merge( $next_block )" Merges the current block with $next_block (the next block encountered) if they're of the same type and are at the same level. This adds the text and args of $next_block to the current block. It's your responsibility to remove $next_block from whatever your code iterates over. o "nests()" Returns true if this block should nest (as in lists and unordered lists) for the active wiki formatting. o "nest( $next_block )" Nests $next_block under this block if the both nest and if $next_block has a level greater than the current block. This actually adds $next_block as a text item within the current block. Beware. AUTHOR
chromatic, "chromatic at wgz dot org" BUGS
No known bugs. COPYRIGHT
Copyright (c) 2006, chromatic. Some rights reserved. This module is free software; you can use, redistribute, and modify it under the same terms as Perl 5.8.x. perl v5.10.1 2011-02-12 Text::WikiFormat::Blocks(3pm)
All times are GMT -4. The time now is 09:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy