Solved

UNIX formatting text file

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

746 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