Sponsored Content
Top Forums Shell Programming and Scripting Working with individual blocks of text using awk Post 302495643 by durden_tyler on Thursday 10th of February 2011 07:22:20 PM
Old 02-10-2011
Here's a Perl script for the problem. Change the value of $delim to "\t" for tab-delimited output.

Code:
$
$ # display the content of the data file "f7"
$ cat -n f7
     1  RCS file: /cvsroot/eclipse/org.eclipse.debug.core/core/org/eclipse/debug/core/IBreakpointListener.java,v
     2  head: 1.14
     3  branch:
     4  locks: strict
     5  access list:
     6  keyword substitution: o
     7  total revisions: 15;    selected revisions: 2
     8  description:
     9  ----------------------------
    10  revision 1.14
    11  date: 2006-06-12 15:42:24 -0500;  author: darin;  state: Exp;  lines: +2 -2;
    12  copyright updates
    13  ----------------------------
    14  revision 1.13
    15  date: 2006-05-16 09:34:00 -0500;  author: darin;  state: Exp;  lines: +1 -1;
    16  javadoc spelling errors
    17  =============================================================================
    18  RCS file: /cvsroot/eclipse/org.eclipse.debug.core/core/org/eclipse/debug/core/IBreakpointManager.java,v
    19  head: 1.36
    20  branch:
    21  locks: strict
    22  access list:
    23  keyword substitution: o
    24  total revisions: 38;    selected revisions: 4
    25  description:
    26  ----------------------------
    27  revision 1.31
    28  date: 2007-03-26 20:47:29 -0500;  author: darin;  state: Exp;  lines: +1 -1;  commitid: 61604608779a4567;
    29  update copyrights
    30  ----------------------------
    31  revision 1.30
    32  date: 2007-01-17 09:01:45 -0600;  author: inigo;  state: Exp;  lines: +3 -2;  commitid: 614345ae3a564567;
    33  javadoc settings and fixes
    34  ----------------------------
    35  revision 1.29
    36  date: 2006-06-12 15:42:24 -0500;  author: montoya;  state: Exp;  lines: +2 -2;
    37  copyright updates
    38  ----------------------------
    39  revision 1.28
    40  date: 2006-05-16 09:34:00 -0500;  author: darin;  state: Exp;  lines: +1 -1;
    41  javadoc spelling errors
    42  =============================================================================
    43  RCS file: /cvsroot/eclipse/org.eclipse.debug.core/core/org/eclipse/debug/core/IBreakpointManagerListener.java,v
    44  head: 1.6
    45  branch:
    46  locks: strict
    47  access list:
    48  keyword substitution: kv
    49  total revisions: 6;    selected revisions: 1
    50  description:
    51  ----------------------------
    52  revision 1.4
    53  date: 2005-02-23 23:58:22 -0600;  author: darins;  state: Exp;  lines: +1 -1;
    54  CPL --> EPL
    55  =============================================================================
$
$
$ # run the Perl script that processes the file "f7"
$
$ perl -lne 'BEGIN {
               $delim = "|";
               print join $delim, ("File", "Total Revisions", "Authors", "Lines Added", "Lines Deleted")
             }
             if (/^RCS file:.*\/(.*?),.*$/) {
               $file = $1;
             } elsif (/^total revisions: (\d+);.*$/) {
               $revcount = $1;
             } elsif (/^.*author: (\w+);.*lines: \+(\d+) -(\d+).*$/) {
               $authors{$1}++;
               $added += $2;
               $deleted += $3;
             } elsif (/^==+$/) {
               print join $delim, ($file, $revcount, join(",", keys %authors), $added, $deleted);
               $file = "";
               $revcount = "";
               %authors = ();
               $added = 0;
               $deleted = 0;
             }
            ' f7
File|Total Revisions|Authors|Lines Added|Lines Deleted
IBreakpointListener.java|15|darin|3|3
IBreakpointManager.java|38|inigo,darin,montoya|7|6
IBreakpointManagerListener.java|6|darins|1|1
$
$

HTH,
tyler_durden
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script not working from crontab, executes individual

Hi, This script is working successfully when i executed from shell prompt, but the same script scheduled in crontab its not deleting the files, #! /bin/bash DAY_1=`(date --date='4 months ago' '+%Y-%m')` log=/tmp/cleant adir=/u01/app/oracle/admin/talon/adump... (4 Replies)
Discussion started by: saha
4 Replies

2. Shell Programming and Scripting

extract blocks of text from a file

Hi, This is part of a large text file I need to separate out. I'd like some help to build a shell script that will extract the text between sets of dashed lines, write that to a new file using the whole or part of the first text string as the new file name, then move on to the next one and... (7 Replies)
Discussion started by: cajunfries
7 Replies

3. Shell Programming and Scripting

How to read text in blocks

Hi, I have file which contains information written in blocks (every block is different). Is it possible to read every block one by one to another file (one block per file). The input is something like this <block1> <empty line> <block2> <empty line> ... ... ... <block25> <empty... (0 Replies)
Discussion started by: art84_)LV
0 Replies

4. Shell Programming and Scripting

how to split this file into blocks and then send these blocks as input to the tool called Yices?

Hello, I have a file like this: FILE.TXT: (define argc :: int) (assert ( > argc 1)) (assert ( = argc 1)) <check> # (define c :: float) (assert ( > c 0)) (assert ( = c 0)) <check> # now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
Discussion started by: paramad
5 Replies

5. Shell Programming and Scripting

Concatenate text between patterns in individual strings

In any given file, wherever a certain data block exists I need to concatenate the values(text after each "=" sign) from that block. in that block. The block starts and ends with specific pattern, say BEGIN DS and END DS respectively. The block size may vary. A file will have multiple such blocks.... (12 Replies)
Discussion started by: Prev
12 Replies

6. Shell Programming and Scripting

Transpose lines from individual blocks to unique lines

Hello to all, happy new year 2013! May somebody could help me, is about a very similar problem to the problem I've posted here where the member rdrtx1 and bipinajith helped me a lot. https://www.unix.com/shell-programming-scripting/211147-map-values-blocks-single-line-2.html It is very... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

7. Shell Programming and Scripting

Adding and removing blocks of text from file

Hello all, short story: I'm writing a script to add and remove dns records in dns files. Its on a RHEL 5.5 So far i've locked up the basic operations in a couple of functions: - validate the parameters - search for existant ip in file when adding - search for existant name records in... (6 Replies)
Discussion started by: maverick72
6 Replies

8. Shell Programming and Scripting

How to remove duplicate text blocks from a file?

Hi All I have a list of files which will have duplicate list of blocks of text. Following is a sample of the file, I have removed the sensitive information from the file. All the code samples starts from <TR BGCOLOR="white"> and Ends with IP address and two html tags like this. 10.14.22.22... (3 Replies)
Discussion started by: mahasona
3 Replies
RCSFREEZE(1)						      General Commands Manual						      RCSFREEZE(1)

NAME
rcsfreeze - freeze a configuration of sources checked in under RCS SYNOPSIS
rcsfreeze [name] DESCRIPTION
rcsfreeze assigns a symbolic revision number to a set of RCS files that form a valid configuration. The idea is to run rcsfreeze each time a new version is checked in. A unique symbolic name (C_number, where number is increased each time rcsfreeze is run) is then assigned to the most recent revision of each RCS file of the main trunk. An optional name argument to rcsfreeze gives a symbolic name to the configuration. The unique identifier is still generated and is listed in the log file but it will not appear as part of the symbolic revision name in the actual RCS files. A log message is requested from the user for future reference. The shell script works only on all RCS files at one time. All changed files must be checked in already. Run rcsclean(1) first and see whether any sources remain in the current directory. FILES
RCS/.rcsfreeze.ver version number RCS/.rcsfreeze.log log messages, most recent first AUTHOR
Stephan v. Bechtolsheim SEE ALSO
co(1), rcs(1), rcsclean(1), rlog(1) BUGS
rcsfreeze does not check whether any sources are checked out and modified. Although both source file names and RCS file names are accepted, they are not paired as usual with RCS commands. Error checking is rudimentary. rcsfreeze is just an optional example shell script, and should not be taken too seriously. See CVS for a more complete solution. GNU RCSFREEZE(1)
All times are GMT -4. The time now is 02:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy