Sponsored Content
Full Discussion: How to parse csv format?
Top Forums Shell Programming and Scripting How to parse csv format? Post 302435007 by chebarbudo on Tuesday 6th of July 2010 07:07:59 AM
Old 07-06-2010
Question How to parse csv format?

Hi,
I have a file with 3 fields in csv format:
Code:
/tmp/foo/,MODIFY,bar/toto
"/tmp/foo, bar/","ATTRIB,ISDIR","toto, tata/foobar"

I would like to split fields in order to obtain the following:
Line1:
Code:
/tmp/foo/
MODIFY
bar/toto

Line2:
Code:
/tmp/foo, bar/
ATTRIB,ISDIR
toto, tata/foobar

Can't find my way through it!
How would you do that?
Thanks for your help.
Santiago
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to Parse a CSV file into a Different Format

Hi I have a CSV file with me in this format Currency, USD, EUR, USD, 1.00, 1.32, EUR, 0.66, 1.00, How do I transpose the file to get to the format below. currency, currency, rate USD, USD, 1.00 USD, EUR, 1.32 EUR, USD, 0.66 EUR, EUR, 1.00 Thanks for your help We are using... (2 Replies)
Discussion started by: cdesiks
2 Replies

2. Shell Programming and Scripting

CSV File parse help in Perl

Folks, I have a bit of an issue trying to obtain some data from a csv file using PERL. I can sort the file and remove any duplicates leaving only 4 or 5 rows containing data. My problem is that the data contained in the original file contains a lot more columns and when I try ro run this script... (13 Replies)
Discussion started by: lodey
13 Replies

3. Shell Programming and Scripting

Unix Script to parse a CSV

I am writing a unix script that will parse a CSV and edit the values. My CSV looks like this 0,0,0,0,1,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0 10,11,7,0,4,12,2,3,7,0,11,3,12,4,0,5,5,4,5,0,8,6,12,0,9,3,3,0,2,7,8... (16 Replies)
Discussion started by: RJ17
16 Replies

4. Shell Programming and Scripting

Parse XML file into CSV with shell?

Hi, It's been a few years since college when I did stuff like this all the time. Can someone help me figure out how to best tackle this problem? I need to parse a file full of entries that look like this: <eq action="A" sectyType="0" symbol="PGR" exch="CA" curr="VEF" sess="NORM"... (7 Replies)
Discussion started by: Pcushing
7 Replies

5. Shell Programming and Scripting

Parse csv file

Hi, Our requirement is to parse the input file(.csv format). The each column in the file is delimited with comma. We need to take each column and apply some business validation rule. If data itself contains comma, then those fields are enclosed with double quotes ("). We can see this double... (7 Replies)
Discussion started by: vfrg
7 Replies

6. 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

7. Shell Programming and Scripting

how to parse this file and obtain a .csv or .xls

Hello Expert, I have a file in the following format: SYNTAX_VERSION 5 MONITOR "NAME_TEMPLATES" DESCRIPTION "Monitors for contents of error " INTERVAL "1m" MONPROG "script.sh NAME_TEMPLATES" MAXTHRESHOLD GEN_BELOW_RESET SEVERITY Major ... (17 Replies)
Discussion started by: Ant-one
17 Replies

8. Shell Programming and Scripting

Parse csv files by their names

HI all I have multiple csv files with the names VAR1_VAR2_VAR3_VAR4.csv All the files have the same structure inside just values change. I am trying to retrieve data from those files by fixing at each time one or more VAR. I tried to write a script but I have 2 problems: 2-... (1 Reply)
Discussion started by: Jhon.c
1 Replies

9. Shell Programming and Scripting

How to parse this file using awk and output in CSV format?

My source file looks like this: Cust-Number = "101" Cust-Name="Joe" Cust-Town="London" Cust-hobby="tennis" Cust-purchase="200" Cust-Number = "102" Cust-Name="Mary" Cust-Town="Newyork" Cust-hobby="reading" Cust-purchase="125" Now I want to parse this file (leaving out hobby) and... (10 Replies)
Discussion started by: Balav
10 Replies

10. Shell Programming and Scripting

Need a script to parse data and output to csv

I am not too savvy with arrays and am assuming that what I am looking for needs arrays. This is my requirement. So I have the raw data that gets updated to a log as shown below StudentInfo: FullInfo = { Address = Newark Age = 20 Name= John } StudentInfo:... (2 Replies)
Discussion started by: sidnow
2 Replies
Template::Plugin::File(3)				User Contributed Perl Documentation				 Template::Plugin::File(3)

NAME
Template::Plugin::File - Plugin providing information about files SYNOPSIS
[% USE File(filepath) %] [% File.path %] # full path [% File.name %] # filename [% File.dir %] # directory DESCRIPTION
This plugin provides an abstraction of a file. It can be used to fetch details about files from the file system, or to represent abstract files (e.g. when creating an index page) that may or may not exist on a file system. A file name or path should be specified as a constructor argument. e.g. [% USE File('foo.html') %] [% USE File('foo/bar/baz.html') %] [% USE File('/foo/bar/baz.html') %] The file should exist on the current file system (unless "nostat" option set, see below) as an absolute file when specified with as leading '"/"' as per '"/foo/bar/baz.html"', or otherwise as one relative to the current working directory. The constructor performs a "stat()" on the file and makes the 13 elements returned available as the plugin items: dev ino mode nlink uid gid rdev size atime mtime ctime blksize blocks e.g. [% USE File('/foo/bar/baz.html') %] [% File.mtime %] [% File.mode %] ... In addition, the "user" and "group" items are set to contain the user and group names as returned by calls to "getpwuid()" and "getgrgid()" for the file "uid" and "gid" elements, respectively. On Win32 platforms on which "getpwuid()" and "getgrid()" are not available, these values are undefined. [% USE File('/tmp/foo.html') %] [% File.uid %] # e.g. 500 [% File.user %] # e.g. abw This user/group lookup can be disabled by setting the "noid" option. [% USE File('/tmp/foo.html', noid=1) %] [% File.uid %] # e.g. 500 [% File.user %] # nothing The "isdir" flag will be set if the file is a directory. [% USE File('/tmp') %] [% File.isdir %] # 1 If the "stat()" on the file fails (e.g. file doesn't exists, bad permission, etc) then the constructor will throw a "File" exception. This can be caught within a "TRY...CATCH" block. [% TRY %] [% USE File('/tmp/myfile') %] File exists! [% CATCH File %] File error: [% error.info %] [% END %] Note the capitalisation of the exception type, '"File"', to indicate an error thrown by the "File" plugin, to distinguish it from a regular "file" exception thrown by the Template Toolkit. Note that the "File" plugin can also be referenced by the lower case name '"file"'. However, exceptions are always thrown of the "File" type, regardless of the capitalisation of the plugin named used. [% USE file('foo.html') %] [% file.mtime %] As with any other Template Toolkit plugin, an alternate name can be specified for the object created. [% USE foo = file('foo.html') %] [% foo.mtime %] The "nostat" option can be specified to prevent the plugin constructor from performing a "stat()" on the file specified. In this case, the file does not have to exist in the file system, no attempt will be made to verify that it does, and no error will be thrown if it doesn't. The entries for the items usually returned by "stat()" will be set empty. [% USE file('/some/where/over/the/rainbow.html', nostat=1) [% file.mtime %] # nothing METHODS
All "File" plugins, regardless of the "nostat" option, have set a number of items relating to the original path specified. path The full, original file path specified to the constructor. [% USE file('/foo/bar.html') %] [% file.path %] # /foo/bar.html name The name of the file without any leading directories. [% USE file('/foo/bar.html') %] [% file.name %] # bar.html dir The directory element of the path with the filename removed. [% USE file('/foo/bar.html') %] [% file.name %] # /foo ext The file extension, if any, appearing at the end of the path following a '"."' (not included in the extension). [% USE file('/foo/bar.html') %] [% file.ext %] # html home This contains a string of the form '"../.."' to represent the upward path from a file to its root directory. [% USE file('bar.html') %] [% file.home %] # nothing [% USE file('foo/bar.html') %] [% file.home %] # .. [% USE file('foo/bar/baz.html') %] [% file.home %] # ../.. root The "root" item can be specified as a constructor argument, indicating a root directory in which the named file resides. This is otherwise set empty. [% USE file('foo/bar.html', root='/tmp') %] [% file.root %] # /tmp abs This returns the absolute file path by constructing a path from the "root" and "path" options. [% USE file('foo/bar.html', root='/tmp') %] [% file.path %] # foo/bar.html [% file.root %] # /tmp [% file.abs %] # /tmp/foo/bar.html rel(path) This returns a relative path from the current file to another path specified as an argument. It is constructed by appending the path to the '"home"' item. [% USE file('foo/bar/baz.html') %] [% file.rel('wiz/waz.html') %] # ../../wiz/waz.html EXAMPLES
[% USE file('/foo/bar/baz.html') %] [% file.path %] # /foo/bar/baz.html [% file.dir %] # /foo/bar [% file.name %] # baz.html [% file.home %] # ../.. [% file.root %] # '' [% file.abs %] # /foo/bar/baz.html [% file.ext %] # html [% file.mtime %] # 987654321 [% file.atime %] # 987654321 [% file.uid %] # 500 [% file.user %] # abw [% USE file('foo.html') %] [% file.path %] # foo.html [% file.dir %] # '' [% file.name %] # foo.html [% file.root %] # '' [% file.home %] # '' [% file.abs %] # foo.html [% USE file('foo/bar/baz.html') %] [% file.path %] # foo/bar/baz.html [% file.dir %] # foo/bar [% file.name %] # baz.html [% file.root %] # '' [% file.home %] # ../.. [% file.abs %] # foo/bar/baz.html [% USE file('foo/bar/baz.html', root='/tmp') %] [% file.path %] # foo/bar/baz.html [% file.dir %] # foo/bar [% file.name %] # baz.html [% file.root %] # /tmp [% file.home %] # ../.. [% file.abs %] # /tmp/foo/bar/baz.html # calculate other file paths relative to this file and its root [% USE file('foo/bar/baz.html', root => '/tmp/tt2') %] [% file.path('baz/qux.html') %] # ../../baz/qux.html [% file.dir('wiz/woz.html') %] # ../../wiz/woz.html AUTHORS
Michael Stevens wrote the original "Directory" plugin on which this is based. Andy Wardley split it into separate "File" and "Directory" plugins, added some extra code and documentation for "VIEW" support, and made a few other minor tweaks. COPYRIGHT
Copyright 2000-2007 Michael Stevens, Andy Wardley. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Template::Plugin, Template::Plugin::Directory, Template::View perl v5.12.1 2008-11-13 Template::Plugin::File(3)
All times are GMT -4. The time now is 02:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy