Sponsored Content
Full Discussion: Script to generate .csv file
Top Forums Shell Programming and Scripting Script to generate .csv file Post 302971187 by RavinderSingh13 on Sunday 17th of April 2016 11:42:08 AM
Old 04-17-2016
Hello abdul2020,

Could you please try following and let me know if this helps you.
Code:
awk -F";" '{gsub(/[[:alpha:]]/,X,$0)} FNR==NR{A[$2]=A[$2]?A[$2] ORS $4 FS $5 FS $6 FS $7 FS $8 FS $9:$4 FS $5 FS $6 FS $7 FS $8 FS $9;next} ($2 in A){print "Time:"$2 ORS "Item_Nu;xw;tr;vyy;ANf;Gk;kl" OFS A[$2];delete A[$2]}'  Input_file   Input_file

Output will be as follows.
Code:
Time:100000
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
1040;54;876;888;;
1060;129;54;87;876;67
1060;54;87;876;67;
1070;129;54;87;876;67
1080;129;87;67;888;
Time:101500
Item_Nu;xw;tr;vyy;ANf;Gk;kl 1010;134;54;87;845;882
1020;169;34;87;576;62
1030;179;24;87;676;62
1040;189;94;87;764;63
1050;134;54;87;63;882
1060;34;87;576;62;883
1070;179;24;87;884;
1080;94;764;63;;
Time:103000
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
1040;125;54;87;876;888

If above doesn't match your requirement completely, then please show us Input_file(more samples) with expected output and all your conditions too, hope this helps.
EDIT: Adding a non-one liner form on same.
Code:
awk -F";" '{
                gsub(/[[:alpha:]]/,X,$0)
           }
                FNR==NR{
                                A[$2]=A[$2]?A[$2] ORS $4 FS $5 FS $6 FS $7 FS $8 FS $9:$4 FS $5 FS $6 FS $7 FS $8 FS $9;
                                next
                       }
           ($2 in A)   {
                                print "Time:"$2 ORS "Item_Nu;xw;tr;vyy;ANf;Gk;kl" OFS A[$2];
                                delete A[$2]
                       }
          '  Input_file  Input_file

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 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
getc_putc(8)						      System Manager's Manual						      getc_putc(8)

NAME
getc_putc - program to test hard drive performance. SYNOPSIS
getc_putc [-d dir] [-s size(KiB)] [-m machine-name] [-u uid-to-use:gid-to-use] [-g gid-to-use] DESCRIPTION
This manual page documents briefly the getc_putc, program. This is a simple adjunct to the bonnie++ benchmark. It is used to test various ways of doing IO one byte at a time, usually you don't need to do enough of this for it to be a performance issue for it to matter much which way you do it. But sometimes it's necessary (for example whan parsing IO from a terminal and then launching another process which will take over all IO, such as a simple shell). The real benefits of this are to help settle some arguements about the performance of such things, and to educate novices about how bad per-byte IO really is. OPTIONS
For getc_putc every option is of the form of a hyphen followed by a letter and then the next parameter contains the value. -d the directory to use for the tests. -s the size of the file for byte IO performance measured in kilobytes. NB You can specify the size in mega-bytes if you add 'm' to the end of the number. The default for this test is to test with a 40MiB file. Of the file only 1/32 of it will be used for write() and read() system calls (anything else takes too long), and only 1/4 of it will be used for locked getc() and putc(). -m name of the machine - for display purposes only. -u user-id to use. When running as root specify the UID to use for the tests. It is not recommended to use root, so if you really want to run as root then use -u root. Also if you want to specify the group to run as then use the user:group format. If you spec- ify a user by name but no group then the primary group of that user will be chosen. If you specify a user by number and no group then the group will be nogroup. -g group-id to use. Same as using :group for the -u parameter, just a different way to specify it for compatibility with other pro- grams. -q quiet mode. If specified then some of the extra informational messages will be suppressed. Also the csv data will be the only output on standard out and the plain text data will be on standard error. This means you can run getc_putc -q >> file.csv to record your csv data. OUTPUT
The primary output is plain-text in 80 columns which is designed to fit well when pasted into email and which will work well with Braille displays. The second type of output is CSV (Comma Seperated Values). This can easily be imported into any spread-sheet or database program. For every test the result is a speed in KiB/s. I do not display the CPU time because it presumably is 99% of the power of a single CPU (or something very close to that). AUTHOR
This program, it's manual page, and the Debian package were written by Russell Coker <russell@coker.com.au>. The documentation, the Perl scripts, and all the code for testing the creation of thousands of files was written by Russell Coker, but the entire package is under joint copyright with Tim Bray. SIGNALS
Handles SIGINT and does a cleanup (which may take some time), a second SIGINT or a SIGQUIT will cause it to immidiately die. SIGXCPU and SIGXFSZ act like SIGINT. Ignores SIGHUP. AVAILABILITY
The source is available from http://www.coker.com.au/bonnie++ . See http://etbe.coker.com.au/category/benchmark for further information. SEE ALSO
bonnie++(8), zcav(8) getc_putc(8)
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy