Solved

UNIX formatting text file

Posted on 2012-04-05
2
511 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
2 Comments
 
LVL 37

Accepted Solution

by:
Gerwin Jansen 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now