Sponsored Content
Top Forums Shell Programming and Scripting Split variable length and variable format CSV file Post 302396772 by radoulov on Friday 19th of February 2010 09:07:55 AM
Old 02-19-2010
Hm,
if it's not too late, you can use something like this:

earnings:

Code:
perl -F, -lane'
next if $. == 1; print join ",", $F[0], @F[4 .. (3 + $F[1]) * 2];
' infile.csv

deductions:

Code:
perl -F, -lane'
next if $. == 1; print join ",", $F[0], @F[(3 + $F[1] * 2) + 1 .. (3 + $F[1] * 2) + $F[2] * 2];
' infile.csv

etc.

For example, given your sample file:

Code:
% perl -F, -lane'
next if $. == 1; print join ",", $F[0], @F[4 .. (3 + $F[1]) * 2];
' infile.csv
1,01,12000,13,1000,14
2,01,10000,02,2000,11,500,12

Code:
% perl -F, -lane'
next if $. == 1; print join ",", $F[0], @F[(3 + $F[1] * 2) + 1 .. (3 + $F[1] * 2) + $F[2] * 2];
' infile.csv
1,13,1000,14,1000
2,11,500,12, 500

Let me know if you still need it, I can help you to incorporate the code in a single program.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

2. Shell Programming and Scripting

use awk to read variable length csv

Any help to read the contents of a variable length csv ....??(using awk) The csv mite look like this : anjali,ram,rahul,mohini,sam,.... and so on ... I need to pick up each name.. Thanks in advance SD (3 Replies)
Discussion started by: shweta_d
3 Replies

3. UNIX for Dummies Questions & Answers

Creating a file in variable length format

Hi all, Does anyone know a technique for creating a download file in variable length format? I have looked around but haven't found any resources on this (or, maybe I'm not sure what to Google for :) ) Thanks in advance! (2 Replies)
Discussion started by: Sarahb29
2 Replies

4. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

5. Shell Programming and Scripting

Parsing a variable length file

Hi I am new to shell scripting. I need to parse a file which contains the header and detail records and split into n of file based on dept ID, for ex. INPUT FILE: DEPT ID: 1 EMPNAME: XYZ EMPAddress: XYZZZ DEPT ID: 2 EMPNAME: ABC EMPAddress: ABCD DEPT ID: 1 EMPNAME: PQR EMPAddress:... (6 Replies)
Discussion started by: singhald
6 Replies

6. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

7. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

8. Shell Programming and Scripting

Parse variable length status,timestamp CSV

I have the output of a process which on status change of the object being processed appends status,timestamp to the record in the text file... so i end up with output something like: task123,TERMINAL,glob,5,INITIAL,2012-02-27 16:48:07,PREPARING,2012-02-27 16:49:06,SCHEDULED,2012-02-27... (2 Replies)
Discussion started by: KarmaPoliceT2
2 Replies

9. Shell Programming and Scripting

Adding a delimiter to a variable length file

Hi, I'm new to unix, i have a variable length file like below, 01|Test|Test1|Sample| 02|AA|BB|CC|DD| 03|AAA|BBB|CCC|DDD|EEE|RRR|TTT|SSS|YYY| I need to make this as a fixed length file. Assume that i have 10 columns in the DAT file. for ex: the first 01 record is having 4cols -... (8 Replies)
Discussion started by: Mohankumar Venu
8 Replies

10. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies
XtVaGetSubvalues()														XtVaGetSubvalues()

Name
  XtVaGetSubvalues - retrieve the current values of subpart resources, using varargs argument style.

Synopsis
  void XtVaGetSubvalues(base, resources, num_resources, ..., NULL)
	   XtPointer base;
	   XtResourceList resources;
	   Cardinal num_resources;

Inputs
  base	    Specifies the base address of the subpart data structure for which the resources should be retrieved.

  resources Specifies the subpart resource list.

  num_resources
	    Specifies the number of resources in the resource list.

  ..., NULL A  NULL-terminated	variable-length  list  of  resource  names and the addresses at which the values of those resources are to be
	    stored.

Availability
  Release 4 and later.

Description
  XtVaGetSubvalues() obtains the values of the resources named in the variable-length argument list  (and  described  in  the  resource  list
  resources)  from  the subpart structure pointed to by base, and stores those values at the addresses specified in the variable length argu-
  ment list.  Note that the special symbol XtVaTypedArg is not supported by XtVaGetSubvalues().  If XtVaTypedArg is specified in the list,  a
  warning message is issued and the entry is then ignored.

  XtVaGetSubvalues()  is  identical  to XtGetSubvalues() except that the args array of resource names and values and the num_args argument of
  that function are replaced with a NULL-terminated variable-length argument list.

  See XtGetSubvalues() for more information on this function.  See XtVaSetValues() for more information  on  using  variable-length  argument
  lists to specify resources.  See XtGetApplicationResources() for information on how to declare an XtResourceList.

See Also
  XtGetApplicationResources(1), XtGetSubvalues(1), XtVaSetValues(1).

Xt - Resource Management													XtVaGetSubvalues()
All times are GMT -4. The time now is 05:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy