Solved

UNIX formatting text file

Posted on 2012-04-05
2
516 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

749 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