Solved

UNIX formatting text file

Posted on 2012-04-05
2
517 Views
Last Modified: 2012-04-05
Hello Experts,

I am trying to process an input text file (basically output of a CVS command) and generate an output file that has all the required details (text) combined together on each line.

So far I have tried using egrep to exlude all the lines with unwanted patterns, and using sed to filter the required text. But, I am unable to combine my output on a single line (output is split over multiple lines).

I need your help to do the follwing:

Thanks,

-Katewadi

INPUT FILE:

RCS file: /was_apps/CCCCIDE/cvsroot/CCCCIDE/src/CCCC/ide/generated/serviceDfn/Attic/ES0434U_SvcDfn.java,v
head: 1.1
branch:
locks: strict
        wasadmin: 1.1
access list:
keyword substitution: kv
total revisions: 3;     selected revisions: 1
description:
----------------------------
revision 1.1.2.2
date: 2012/04/04 18:10:54;  author: UserID-1;  state: Exp;  lines: +1 -1
CCCCUAT-1145
=============================================================================

RCS file: /was_apps/CCCCIDE/cvsroot/CCCCIDE/src/CCCC/ide/generated/serviceDfn/Attic/ES0434U_SvcDfn.java,v
head: 1.1
branch:
locks: strict
        wasadmin: 1.1
access list:
keyword substitution: kv
total revisions: 3;     selected revisions: 1
description:
----------------------------
revision 1.1.2.2
date: 2012/04/04 18:10:54;  author: UserID-2;  state: Exp;  lines: +1 -1
CCCCUAT-1146
=============================================================================

OUTPUT: to a Textfile

/was_apps/CCCCIDE/cvsroot/CCCCIDE/src/CCCC/ide/generated/serviceDfn/Attic/ES0434U_SvcDfn.java,v, 1.1.2.2, 2012/04/04 18:10:54, UserID-1,CCCCUAT-1145
/was_apps/CCCCIDE/cvsroot/CCCCIDE/src/CCCC/ide/generated/serviceDfn/Attic/ES0434U_SvcDfn.java,v, 1.1.2.2, 2012/04/04 18:10:54, UserID-2,CCCCUAT-1146
0
Comment
Question by:Katewadi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 500 total points
ID: 37813662
Hi, you can use awk to split your input file into fields (multi line record feature). Then look for what you need in each field, do some substitutions and print the output.

Create your awk file like this and name it something like parse.awk
BEGIN { FS="\n" ; RS="" }
{
        p1=$1
        sub(/RCS file: /, "", p1)
        p2=$11
        sub(/revision/, "", p2)
        p3=$12
        sub(/date:/, "", p3)
        sub(/; *author: /, ", ", p3)
        sub(/;.*$/, "", p3)
        p4=$13
        print p1 "," p2 "," p3 "," p4
}

Open in new window

Assuming your input file is named input.txt then process your input like this:
awk -f parse.awk input.txt > output.txt

Open in new window

I tested and got this output:

/was_apps/CCCCIDE/cvsroot/CCCCIDE/src/CCCC/ide/generated/serviceDfn/Attic/ES0434U_SvcDfn.java,v, 1.1.2.2, 2012/04/04 18:10:54, UserID-1,CCCCUAT-1145
/was_apps/CCCCIDE/cvsroot/CCCCIDE/src/CCCC/ide/generated/serviceDfn/Attic/ES0434U_SvcDfn.java,v, 1.1.2.2, 2012/04/04 18:10:54, UserID-2,CCCCUAT-1146
0
 

Author Closing Comment

by:Katewadi
ID: 37814113
That works for me.

Thanks for your help!

-Katewadi
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question