?
Solved

UNIX formatting text file

Posted on 2012-04-05
2
Medium Priority
?
518 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 2000 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

764 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