LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 05-04-2005, 01:47 PM   #1
jonlake
Member
 
Registered: Apr 2004
Distribution: Slackware 11.0, Gentoo
Posts: 252

Rep: Reputation: 31
awk question


I have a file named output and it is formatted like this

uid=xxxxxxxx
mail=xxxxxxxxxxx
usfvaultgrp=SECURITY
usfvaultuserkey=mOiGd+od8is=
USFLdapAdminRole=super
cn=Walter
sn=Walter
gecos=Scott Walter
objectClass=top
objectClass=person
objectClass=organizationalPerson
objectClass=inetorgperson
objectClass=posixAccount
objectClass=shadowAccount
objectClass=account
objectClass=usfperson
telephoneNumber=xxxxxxx
givenName=Scott
homeDirectory=/net/home/swalter
gidNumber=7
uidNumber=1003
uid=swalter
loginShell=/bin/ksh

uid=TSC
mail=xxxxxxxxxxxxx
objectClass=top
objectClass=person
objectClass=organizationalPerson
objectClass=inetorgperson
telephoneNumber=xxxxxxxxx
givenName=Help
sn=Desk
uid=TSC
cn=Help Desk

with many more sections. I am putting a line in my script that says
Code:
awk '{ FS="\n" ; OFS="," ; RS="^$" ; ORS="\n" ; print ; }' output > file
My understanding is it should take each line in a section, change it to a csv line, and each section should be a new line. However, I get an error
Code:
migrrufrsa01:jlake> ./script
awk: record `mail=xxxxxxxxxxxxxxxx...' too long
 record number 1
host:jlake>

Last edited by jonlake; 05-04-2005 at 01:50 PM.
 
Old 05-04-2005, 04:38 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
This site has an example which may be what you're after
http://www-106.ibm.com/developerwork...ry/l-awk2.html

I run it like this: awk -f test file.txt > file1.txt
Code:
#!/bin/bash

BEGIN {
    FS="\n"
    RS=""
    ORS=""
}

{
        x=1
        while ( x<NF ) {
                print $x ","
                x++
        }
        print $NF "\n\n"
}
Edit: I changed this to give better record separation....
print $NF "\n\n"

Last edited by homey; 05-04-2005 at 04:50 PM.
 
Old 05-04-2005, 04:58 PM   #3
jonlake
Member
 
Registered: Apr 2004
Distribution: Slackware 11.0, Gentoo
Posts: 252

Original Poster
Rep: Reputation: 31
Ok I want to go a different way than I initially though, when I posted this.

I want to print out the UID, CN, GECOS, Mail, Telephone, Homedirectory in each column.
I got that I can setup each section as a record, and each line as a field. As you can see, they aren't always the same field (cn would be $6 on the first record, and $11 on the second). I only want these fields, in the specified order. I know how to do it if they were in the same order everytime, but they aren't.

Currently I am to the point of where sed gets rid of the unneeded lines (although i can't get rid of the first uid line) and as said before, can get awk to see each section as a record, and each line as a field.

Thanks,

Jon
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
awk question puishor Programming 2 08-26-2005 10:44 AM
awk question denalitastic Linux - Newbie 1 06-07-2005 11:42 AM
AWK question paraiso Linux - Newbie 5 05-12-2005 02:37 PM
awk question dilberim82 Programming 2 10-01-2003 08:12 PM
awk question (mandrake 8.2) Frauke Linux - Newbie 0 09-19-2002 05:05 PM


All times are GMT -5. The time now is 12:59 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration