Sponsored Content
Full Discussion: Script to generate .csv file
Top Forums Shell Programming and Scripting Script to generate .csv file Post 302971205 by RudiC on Sunday 17th of April 2016 04:38:13 PM
Old 04-17-2016
Please consider a precise and detailed specification next time, like
- tags (or field names) are reflected in the header except for the first header field that is NOT found back in the data records but should be filled with data field 4
- fields are separated by ";"
- data field 3 is the time stamp and should be printed with every change after separation of its field name
- data field 4 needs to lose its field name and trailer and then to be printed as first field per line
- alpha only field name of arbitrary length is leading the fields, numerical field values follow without separator
- fields should be printed according to their position in the header.
etc. etc. etc.

Wildly guessing on what MIGHT BE required, I came up with
Code:
awk -F";" '
BEGIN           {HDStr = "Item_Nu;xw;tr;vyy;ANf;Gk;kl"
                 HDCNT = split (HDStr, HD)
                }

$3 != LAST      {LAST = $3
                 gsub (/[^0-9]|.$/, _, $3)
                 print "Time: " $3
                 print HDStr
                }

                {for (i=5; i<=NF; i++)  {IX = match ($i, /[0-9]/)
                                         RES[substr ($i, 1, IX-1)] = substr ($i, IX)
                                        }
                 gsub (/[^0-9]/, _, $4)
                 printf "%s", $4
                 for (i=2; i<=HDCNT; i++)       {printf ";%s", RES[HD[i]]
                                                }
                 printf "\n"
                 split ("", RES)
                }

' file
Time: 101500
Item_Nu;xw;tr;vyy;ANf;Gk;kl
1010;129;54;87;;67;888
1020;129;54;87;876;67;
1030;129;54;87;876;67;888
1040;;54;;876;;888
1060;129;54;87;876;67;888
1060;;54;87;876;67;
1070;129;54;87;876;67;888
1080;129;;87;;67;888
Time: 103000
Item_Nu;xw;tr;vyy;ANf;Gk;kl
1010;134;54;87;845;;882
1020;169;34;87;576;62;883
1030;179;24;87;676;62;884
1040;189;94;87;764;63;885
1050;134;54;87;;63;882
1060;;34;87;576;62;883
1070;179;24;87;;;884
1080;;94;;764;63;
Time: 104500
Item_Nu;xw;tr;vyy;ANf;Gk;kl
1010;;84;87;976;67;888
1020;129;74;87;;67;888
1030;139;64;87;876;67;888
1040;125;54;87;876;;888

This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate csv file

I have a file which has some thousand records in the following format File: input.txt -> <option value="14333">VISWANADH VELAMURI</option> <option value="17020">VISWANADHA RAMA KRISHNA</option> I want to generate a csv file from the above file as follows File: output.txt -> ... (4 Replies)
Discussion started by: rahulrathod
4 Replies

2. UNIX for Dummies Questions & Answers

generate CSV file using AWK script

Hi guys I have a text report that consists of text in some parts and data in some parts. e.g Report for changes in cashflows No changes were found Report for changes in Bills deal_num deal_date trader maturity log_creator DF_234 20-5-2008 tman 20-5-2009 tman... (2 Replies)
Discussion started by: magikminox
2 Replies

3. Shell Programming and Scripting

need help in Parsing a CSV file and generate a new output file

Hi Scripting Gurus, I am trying to parse a csv file and generate a new output file. The input file will be a variable length in turns of rows and columns. output file will have 8 columns. we have three columns from the header for each set. just to give little bit more clarification each row... (15 Replies)
Discussion started by: vkr
15 Replies

4. Shell Programming and Scripting

Need to generate .csv file

I have a csv file with the following data Please find the attachment - zip ... (6 Replies)
Discussion started by: vaas
6 Replies

5. Shell Programming and Scripting

to read a CSV file and generate SQL output

Friends, This is what I need: I will pass a CSV file as an input, and I want my shell to be reading that CSV file, and based on the parameters it should generate SQLs and write those SQL in a different file in the same location. I'm new to Shell scripting. I'm currently working on a... (1 Reply)
Discussion started by: Ram.Math
1 Replies

6. Shell Programming and Scripting

Read a CSV file and generate SQL output

Friends, This is what I need: I will pass a CSV file as an input, and I want my shell to be reading that CSV file, and based on the parameters it should generate SQLs and write those SQL in a different file in the same location. I'm new to Shell scripting. I'm currently working on a... (25 Replies)
Discussion started by: Ram.Math
25 Replies

7. Shell Programming and Scripting

Script to generate csv file

Hello; I need to generate a csv file that contains a list of all the files in a particular server (from the root directory ie: \) that have a permission stamp of 777. I would like to create the csv so that it contains the following: server name, file name, full path name where file exists,... (17 Replies)
Discussion started by: gvolpini
17 Replies

8. Shell Programming and Scripting

BASH script to parse XML and generate CSV

Hi All, Hope all you are doing good! Need your help. I have an XML file which needs to be converted CSV file. I am not an expert of awk/sed so your help is highly appreciated!! XML file looks like this: <l:event dateTime="2013-03-13 07:15:54.713" layerName="OSB" processName="ABC"... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

9. Shell Programming and Scripting

Script to generate csv file

Dears, I am new in shell world and I need your help in this, I have to create a report based on the output file generated by another program. I want to write a shell script for this. The output file generated every 15 minutes but i can’t open it until the end of day so the script will get the... (3 Replies)
Discussion started by: abdul2020
3 Replies

10. Shell Programming and Scripting

Generate .csv/ xls file report

There can be thousand of .ksh in a specific directory where sql files are called from ksh. Requirement is to loop through all the files content and generate a report like below: Jobname Type type sqlname gemd1970 sql daily tran01 gemw1971 sql weekly ... (6 Replies)
Discussion started by: vedanta
6 Replies
NPM-RUN-SCRIPT(1)                                                                                                                NPM-RUN-SCRIPT(1)

NAME
npm-run-script - Run arbitrary package scripts SYNOPSIS
npm run-script <command> [--silent] [-- <args>...] alias: npm run DESCRIPTION
This runs an arbitrary command from a package's "scripts" object. If no "command" is provided, it will list the available scripts. run[-script] is used by the test, start, restart, and stop commands, but can be called directly, as well. When the scripts in the package are printed out, they're separated into lifecycle (test, start, restart) and directly-run scripts. As of ` https://blog.npmjs.org/post/98131109725/npm-2-0-0, you can use custom arguments when executing scripts. The special option -- is used by getopt https://goo.gl/KxMmtG to delimit the end of the options. npm will pass all the arguments after the -- directly to your script: npm run test -- --grep="pattern" The arguments will only be passed to the script specified after npm run and not to any pre or post script. The env script is a special built-in command that can be used to list environment variables that will be available to the script at run- time. If an "env" command is defined in your package, it will take precedence over the built-in. In addition to the shell's pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts. Any binaries provided by locally-installed dependencies can be used without the node_modules/.bin prefix. For example, if there is a devDependency on tap in your package, you should write: "scripts": {"test": "tap test/*.js"} instead of "scripts": {"test": "node_modules/.bin/tap test/*.js"} to run your tests. The actual shell your script is run within is platform dependent. By default, on Unix-like systems it is the /bin/sh command, on Windows it is the cmd.exe. The actual shell referred to by /bin/sh also depends on the system. As of ` https://github.com/npm/npm/releases/tag/v5.1.0 you can customize the shell with the script-shell configuration. Scripts are run from the root of the module, regardless of what your current working directory is when you call npm run. If you want your script to use different behavior based on what subdirectory you're in, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run. npm run sets the NODE environment variable to the node executable with which npm is executed. Also, if the --scripts-prepend-node-path is passed, the directory within which node resides is added to the PATH. If --scripts-prepend-node-path=auto is passed (which has been the default in npm v3), this is only performed when that node executable is not found in the PATH. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install, just in case you've forgotten. You can use the --silent flag to prevent showing npm ERR! output on error. You can use the --if-present flag to avoid exiting with a non-zero exit code when the script is undefined. This lets you run potentially undefined scripts without breaking the execution chain. SEE ALSO
o npm help 7 scripts o npm help test o npm help start o npm help restart o npm help stop o npm help 7 config January 2019 NPM-RUN-SCRIPT(1)
All times are GMT -4. The time now is 04:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy