Sponsored Content
Top Forums Shell Programming and Scripting Converting form field to table format Post 302605952 by ygemici on Friday 9th of March 2012 07:28:57 AM
Old 03-09-2012
Quote:
Originally Posted by before4
Thank you.. but i can got the wrong output and also did not work for Name field more than 1 word( ie. Andi ruby) and when the field has empty value
Code:
$ awk -V | head -1
GNU Awk 4.0.0

$ cat data.txt
   Name = Andi
Address = none
   Phone = 82728

   Name = Peter
Address = none
   Phone = 98799

$ awk -vfs=',' 'BEGIN{printf "%s%s%s\n","Name"fs,"Address"fs,"Phone";}{ \
if($0!~/^ *$/) a[++x]=$NF;else b[x]=x-1};END{for(i=1;i<=x;i++)if(i-1==b[i]&&b[i]!=0||i==x)printf "%s\n",a[i]; \
else{printf "%s"fs,a[i]}}' data.txt
Name,Address,Phone
Andi,none,82728,                                         ,Peter,none,98799

1-)how about your input file?
Code:
# od -c input

2-) what is your system?

and
i modified code for other your requests(more than 1 word or empty)..
and i tried for gawk 4.0 but results are same as i think,
maybe your input file has contain different charset.
Code:
# cat testfile
Name =
Address = Oklahoma city
   Phone = 82728

   Name = Peter Surname
Address = none
   Phone = 98799

   Name = John
Address = NJ City
   Phone = 10000

   Name = Mr.Smith
Address =
   Phone = 5555555 555555

Code:
# gawk2 -V|grep "GNU AWK" -i
GNU Awk 4.0.0

Code:
# gawk2 -vfs=',' 'BEGIN{printf "%s%s%s\n","Name"fs,"Address"fs,"Phone";}
{if($0!~/^ *$/){s=gensub(".*=[\t ]*(.*)","\\1",$0);
if(match(s,"[^\t ]"))a[++x]=s;else a[++x]="XXX"}else b[x]=x-1}
END{for(i=1;i<=x;i++)if(i-1==b[i]&&b[i]!=0||i==x)printf "%s\n",a[i]; else printf "%s"fs,a[i]}' testfile
Name,Address,Phone
XXX,Oklahoma city,82728
Peter Surname,none,98799
John,NJ City,10000
Mr.Smith,XXX,5555555 555555

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting %## back to special characters from an HTML form

I have an HTML form that sends email to a large list of users one at a time by matching an email address in peoplesoft to their username. It works great, except that special characters are converted to %## format. Is there a library of these I can use to sed them back (yes this is a crappy UNIX... (1 Reply)
Discussion started by: 98_1LE
1 Replies

2. Shell Programming and Scripting

help on formatting output (Table Form)

Data in File ABC:DEFGHI:123 ABCZYE:DEFI:123 ABCFGD:DEF:123 ABCEERRRRR:DEFGHI:123 Expected Format 1 ABC DEFGHIFE 123 2 ABCZYE DEFI 123 3 ABCFGD DEF 123 4 ABCEERRRRR DEFGHI 123 However when i enter the following... (2 Replies)
Discussion started by: blurboy
2 Replies

3. Shell Programming and Scripting

Converting html table data into multiple variables.

Hi, Basically what I am trying to do is the following. I have created a shell script to grab timetabling information from a website using curl then I crop out only the data I need which is a table based on the current date. It leaves me with a file that has the table I want plus a small amount... (2 Replies)
Discussion started by: domsmith
2 Replies

4. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

5. Shell Programming and Scripting

Cgi to dump xml data from form input field

Hi All, I am trying to write a shell script which takes parse the web form find the input field and dump the data of that field into one xml file. The form looks like, <input type="button" id="btnSave" value="Save" onclick="saveXmlData()"/> <form name="submitForm"... (1 Reply)
Discussion started by: jdp
1 Replies

6. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

7. Shell Programming and Scripting

Getting data in table form

Hi, I have a csv file from which i am fetching few columns as below: IFILE=/home/home1/Report1.csv OFILE=/home/home1/`date +"%m%d%y%H%M%S"`.dat if #Checks if file exists and readable then awk -F "," '(NR>4) {print $1,$6,$2,$3,$4,$5,$6}' ${IFILE} >> ${OFILE} fi cat $OFILE | mail... (7 Replies)
Discussion started by: Vivekit82
7 Replies

8. Web Development

Php help to copy form field if empty

I have an input form with several fields. What I would like to achieve is to auto populate or copy certain fields if they are empty when the form is submitted. I would like to use php if not then javascript but not jquery if possible - I have sort of had a go but I really have no idea... (4 Replies)
Discussion started by: barrydocks
4 Replies

9. Shell Programming and Scripting

JSON structure to table form in awk, bash

Hello guys, I want to parse a JSON file in order to get the data in a table form. My JSON file is like this: { "document":{ "page": }, { "column": } ] }, { ... (6 Replies)
Discussion started by: Gescad
6 Replies
ldaptemplates.conf(4)						   File Formats 					     ldaptemplates.conf(4)

NAME
ldaptemplates.conf - configuration file for LDAP display template routines SYNOPSIS
/etc/opt/SUNWconn/ldap/current/ldaptemplates.conf DESCRIPTION
The ldaptemplates.conf file contains information used by the LDAP display routines. Blank lines and lines that start with a hash character ('#') are treated as comments and ignored. Non-comment lines contain one or more tokens. Tokens are separated by white space, and double quotes can be used to include white space inside a token. The first non-commment line specifies the version of the template information and must contain the token Version followed by an integer version number. For example, Version 1 The current version is 1, so the above example is always the correct first line. The remainder of the file consists of one or more display templates. The first two lines of the display template each contain a single token that specifies singular and plural names for the template in a user-friendly format. For example, "Person" "People" specifies appropriate names for a template designed to display person information. The next line specifies the name of the icon or similar element that is associated with this template. For example, "person icon" The next line is a blank-separated list of template options. "" can be used if no options are desired. Available options are: addable (it is appropriate to allow entries of this type to be added), modrdn (it is appropriate to offer the modify rdn operation), altview (this tem- plate is an alternate view of another template). For example, "addable" "modrdn" The next portion of the template is a list of X.500 object classes that is used to determine whether the template should be used to display a given entry. The object class information consists of one or more lines, followed by a terminating line that contains the single token END. Each line contains one or more object class names, all of which must be present in a directory entry. Multiple lines can be used to associate more than one set of object classes with a given template. For example, emailPerson orgPerson END means that the template is appropriate for display of emailPerson entries or orgPerson entries. The next line after the object class list is the name of the attribute to authenticate as to make changes (use "" if it is appropriate to authenticate as the entry itself). For example, "owner" The next line is the default attribute to use when naming a new entry, for example, "cn" The next line is the distinguished name of the default location under which new entries are created. For example, "o=XYZ, c=US" The next section is a list of rules used to assign default values to new entries. The list should be terminated with a line that contains the single token END. Each line in this section should either begin with the token constant and be followed by the name of the attribute and a constant value to assign, or the line should begin with addersdn followed by the name of an attribute whose value will be the DN of the person who has authenticated to add the entry. For example, constant associatedDomain XYZ.us addersdn seeAlso END The last portion of the template is a list of items to display. It consists of one or more lines, followed by a terminating line that con- tains the single token END. Each line is must begin with the token samerow or the token item It is assumed that each item appears on a row by itself unless it was preceded by a samerow line (in which case it should be displayed on the same line as the previous item, if possible). Lines that begin with samerow should not have any other tokens on them. Lines that begin with item must have at least three more tokens on them: an item type, a label, and an attribute name. Any extra tokens are taken as extra arguments. The item type token must be one of the following strings: cis case-ignore string attributes mls multiline string attributes mail RFC-822 conformant mail address attributes dn distinguished name pointer attributes bool Boolean attributes jpeg JPEG photo attributes jpegbtn a button that will retrieve and show a JPEG photo attribute fax FAX T.4 format image attributes faxbtn a button that will retrieve and show a FAX photo attribute audiobtn audio attributes time UTC time attributes date UTC time attributes where only the date portion should be shown url labeled Uniform Resource Locator attributes searchact define an action that will do a directory search for other entries linkact define an action which is a link to another display template protected for an encrypted attribute, with values displayed as asterisks An example of an item line for the drink attribute (displayed with label "Work Phone"): item cis "Work Phone" telephoneNumber EXAMPLES
Example 1: A Sample Configuration File Containing a Template that Displays People Entries The following template configuration file contains a templates for display of people entries. # # LDAP display templates # # Version must be 1 for now # Version 1 # # Person template "Person" "People" # name of the icon that is associated with this template "person icon" # blank-separated list of template options ("" for none) "addable" # # objectclass list person END # # name of attribute to authenticate as ("" means auth as this entry) "" # # default attribute name to use when forming RDN of a new entry # "cn" # # default location when adding new entries (DN; "" means no default) "o=XYZ, c=US" # # rules used to define default values for new entries END # # list of items for display item jpegbtn "View Photo" jpegPhoto "Next Photo" item audiobtn "Play Sound" audio item cis "Also Known As" cn item cis "Title" title item mls "Work Address" postalAddress item cis "Work Phone" telephoneNumber item cis "Fax Number" facsimileTelephoneNumber item mls "Home Address" homePostalAddress item cis "Home Phone" homePhone item cis "User ID" uid item mail "E-Mail Address" mail item cis "Description" description item dn "See Also" seeAlso END ATTRIBUTES
See attributes(5) for a description of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWlldap | +-----------------------------+-----------------------------+ |Stability Level |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
ldap_disptmpl(3LDAP), ldap_entry2text(3LDAP), attributes(5) SunOS 5.10 9 Jul 2003 ldaptemplates.conf(4)
All times are GMT -4. The time now is 11:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy