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
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 07:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy