Sponsored Content
Full Discussion: CSV data format manipulation
Top Forums Shell Programming and Scripting CSV data format manipulation Post 302702003 by rdrtx1 on Monday 17th of September 2012 05:43:22 PM
Old 09-17-2012
Code:
 
awk -f a.awk s1.csv

where a.awk:

Code:
 
{
 FS=",";
 if ($1 != lr) {
    printf "ONE Rec";
    for (i=1; i<=NF; i++) {
     printf "," $(i);
     if (i > 11) break;
    }
    print ",";
 }
 printf "Child Record";
 for (i=13; i<=NF; i++) {
  printf "," $(i);
 }
 print "";
 lr=$1;
}

using input file attached...

output:

Code:
ONE Rec,Milani,3501,REST,HINAM-FAST,HINAM & CO,222 Snooker GREEN STATION,Mumbai MA  10274,,,2,NY,13-2555119,
Child Record,4/17/2012,1.277,3/15/2012,57.08,59.04,0,,S,SHORT,Y,HINAM,4,10274
Child Record,6/26/2012,0.7321,6/15/2012,33.71,34.11,0,,S,SHORT,Y,HINAM,4,10274
Child Record,7/31/2012,0.3811,6/15/2012,18.41,17.77,0,,S,SHORT,Y,HUG J MCMENAMIN,2,23060-7241
Child Record,5/1/2012,13,,593.54,,0,,,,N,MAR J STRANGER,4,53963-2286
Child Record,3/27/2012,23,,"1,020.55",,0,,,,N,BAR KSHINAP,1,54457-9291
Child Record,2/14/2012,503.7475,,"22,918.40",,0,,,,N,EDW A DIGGS,1,46805-2652
ONE Rec,DRS,54029,55277PDRS,LARRY C KISSIME & SMUTTY S KISSIME TR,UA 04 02 03,LARRY C & SMUTTY S KISSIME LIV TRUST,442 NINJAY VALLEY RD,MOUNT HOREB WI  53572-3016,,,WI,XXX-XX-3555,
Child Record,6/19/2012,170,,"8,049.45",,0,,,,N,LAR C KISSIME,2,53572-3016
Child Record,5/15/2012,4.4864,,205.75,,0,,,,N,JUL NONO,1,07045-9563

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to format a .CSV data

Hi There I needed to write a Unix shell script which will pick up the data from a .CSV file and reformat it as per the requirement and write it to another .CSV file. Currently I am in the proess of Data Import to "Remedy System" (A one kind of incident mangement Application) and this... (8 Replies)
Discussion started by: Uday1982
8 Replies

2. UNIX for Advanced & Expert Users

shell script to format .CSV data

Hi all, I have written a shell script to search a specified directory (e.g. /home/user) for a list of specific words (shown as ${TMPDIR}/wordlist below). The script works well enough, but I was wondering if there was a way to display the line number that the word is found on? Thanks! cat... (1 Reply)
Discussion started by: tmcmurtr
1 Replies

3. Shell Programming and Scripting

Retaining the Unix CSV format in Excel format while exporting

Hi All, I have created a Unix Shell script whch creates a *.csv file and export it to Excel. The problem i am facing is that Users wants one of the AMOUNT field in comma separted values. Example : if the Amount has the value as 3000000 User wants to be in 3,000,000 format. This Amount format... (2 Replies)
Discussion started by: rawat_me01
2 Replies

4. Shell Programming and Scripting

Conversion of xhtml data into csv format using dump utility

Hi Unix Gurus, I tried to convert the attached xhtml table content into csv file using unix shell script (lynx -dump filename) and got the below results: Title ID Owner Priority Estimate Project Change Date Changed By Complexity Create Date Created By Detail Estimate Total De tail... (6 Replies)
Discussion started by: bi.infa
6 Replies

5. Shell Programming and Scripting

Data Manipulation on a .csv file

Hallo Friends, I need you help. My file has 5000 or so lines and currently looks like below(sample). Service Type,Origin,Destination,Rate Per Minute,Minimum Charge,Time Based Rate,Time Based From Day,Time Based To Day,Time Based From Time,Time Based To Time,Destination Prefix List,, VoIS... (3 Replies)
Discussion started by: kekanap
3 Replies

6. Shell Programming and Scripting

LDAP data in CSV format

Hi all, I am new here, please don't eat me alive.. I am trying to find a good community to learn and participate in unix / linux discussions to help me improve in my current job. That being said, I have a problem which I didn't expect to challenge me, but I can't seem to find a viable... (8 Replies)
Discussion started by: tfm217
8 Replies

7. Shell Programming and Scripting

LDAP data in CSV format - Part II

User Aia had created this below script to help translate LDIF files to CSV format, and it works very well (thanks again Aia if you are reading this) Here is the original thread. https://www.unix.com/shell-programming-and-scripting/265753-ldap-data-csv-format.html?referrerid=302170129 However... (2 Replies)
Discussion started by: tfm217
2 Replies

8. Shell Programming and Scripting

Convert csv data to html format

I am new to html and need to convert the attached csv file data to html format ; running into issues. please assist. #!/bin/ksh echo "<html>" ; echo "<head><style> table {border-collapse: collapse;} table, td, th {border: 1px solid black;} </style></head>" echo "<title> REPORT </title>" echo... (0 Replies)
Discussion started by: archana25
0 Replies

9. Shell Programming and Scripting

Can we filter the below log data into CSV format?

HI , I m looking for help here!!! Can we filter the below log data into CSV format ? timestamp INFO <text > - Some text Drive .. Need a format of separate field such as 1 2 3 4 ... (2 Replies)
Discussion started by: MohSalNiz
2 Replies

10. UNIX for Beginners Questions & Answers

Log file data into CSV format

I m looking for help here!!! Can we filter the below log data into CSV format ? 1 2 3 4 5 6 7 8 timestamp INFO <text > - Some text (1 Reply)
Discussion started by: MohSalNiz
1 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWgawk | +--------------------+-----------------+ |Interface Stability | Volatile | +--------------------+-----------------+ NOTES
Source for gawk is available on http://opensolaris.org. Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy