Sponsored Content
Top Forums Shell Programming and Scripting Randomly inserting extra columns into csv file Post 302855381 by Lokesha on Thursday 19th of September 2013 05:15:40 PM
Old 09-19-2013
Code Randomly inserting extra columns into csv file

Hi Tech Guru,

I have a test file as below [in reality its a very big file], which needs some more fields to be populated randomly :

Code:
dks3243;12;20130823;1420;25m;0;syt
dks3243;rocy;10
dks3243;kiop;18
sde21p4;77;20151210;8479;7py;9;vfr
sde21p4;temp;67
sfq6i01;12;20120123;3412;4rd;7;jui
sfq6i01;uymk;90
sfq6i01;kiop;51



requirement 1) I need to insert 3 columns with random date values [format yyyymmdd] inside one test file.
Condition:
A. These 3 new random date fields should be inserted only if the total number of the columns are more than 3.
B. These new columns should be insert in the position of 5,6,7 in test file.
C. I need to insert a flag value 'Y' or 'N' as new position 9. [if possible 'Y' for some lines and 'N' for some lines randomly]

Code:
dks3243;12;20130823;1420;20120101;20141231;20150812;25m;J;0;syt
dks3243;rocy;10
dks3243;kiop;18
sde21p4;77;20151210;8479;20080812;20111012;20030218;7py;N;9;vfr
sde21p4;temp;67
sfq6i01;12;20120123;3412;20070315;20180918;20121217;4rd;Y;7;jui
sfq6i01;uymk;90
sfq6i01;kiop;51




Shell script, sed, awk or perl any thing is OK for me to achieve this tough work. Any help will be much appreciated.

Thanks,
Lokesh

Last edited by Lokesha; 09-19-2013 at 07:02 PM.. Reason: Correction - changed flag to 'Y' from 'J'.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

use awk to read randomly located columns in an excel file

Hi, I have an excel file that have a random count of columns/fields and what im trying to do is to only retrieve all the rows under 2 specific field headers. I can use the usually command for awk which is awk 'print{ $1 $2}' > output.txt, but the location of the 2 specific field headers is... (9 Replies)
Discussion started by: mdap
9 Replies

2. Shell Programming and Scripting

Inserting 2 columns from a file to another with nawk

Hello all, I have these 2 files File1 123 100 456 200 789 300 File2 |1|2|3||4|5||6| |1|2|3||4|5||6| |1|2|3||4|5||6| I need an output like : |1|2|3|123|4|5|100|6| |1|2|3|456|4|5|200|6| |1|2|3|789|4|5|300|6| (3 Replies)
Discussion started by: rany1
3 Replies

3. Shell Programming and Scripting

Ascii Mode appending extra records to csv file

I am relatively new to this forum and Unix scripting. ksh script: part 1 :will call a PL\SQL program will create 3 CSV file at the unix directory. part 2 : will sftp the files to the EFT server. Once the EFT server receives these file , it will transfer them to a shared windows folders. ... (3 Replies)
Discussion started by: developerpa
3 Replies

4. Shell Programming and Scripting

Adding Extra Commas to a CSV file

Trying in this forum. Not sure if it is permitted.... but in need of help. Please find the requirements in the below link. https://www.unix.com/unix-dummies-questions-answers/191503-add-extra-commas-csv-file-2.html#post302665179 Thanks in Advance. (1 Reply)
Discussion started by: chillblue
1 Replies

5. UNIX for Dummies Questions & Answers

To Add extra commas to a CSV file using 2 files...

Hi , Based on my previous requirement the code works fine for comma as delimiter. Now my Req is widened up a bit .. There will be two set of files .. one with comma as delimiter and other with semi-colon ; as delimiter. Second Sample file. With Double Quotes (Semi-Colon... (1 Reply)
Discussion started by: chillblue
1 Replies

6. UNIX for Dummies Questions & Answers

To Add extra commas to a CSV file.

Hi All, I got this requirement to process a complex CSV file. Eg File. Line 1: Name:,XYz Line 2: Age:,15 Line 3: Grade:,7 Line 4: Line 5: English, Maths, Science,Spanish Line 6:10,11,13,14 As you can see the maximum column is 4 . The file i need to make is Line 1: Name:,XYz,,... (12 Replies)
Discussion started by: chillblue
12 Replies

7. Shell Programming and Scripting

Inserting new fields to a csv file

hi I have a csv file with few rows > cat job_stat 1,jobname1,somthing,somthing 2,jobname2,somthing,somthing 3,jobname3,somthing,somthing 4,jobname4,somthing,somthing I want to add few columns after the 2nd column and then append rest of the columns after the 3rd newly added... (3 Replies)
Discussion started by: midhun19
3 Replies

8. Shell Programming and Scripting

Inserting blank columns in already present CSV file

Hi, i have a csv file which have headers and values of it like below : headers --> CI Ref SerialNumber LastScanDate values --> VMware-42,VMware-42,Tue, 20 May 2014 11:03:44 +0000 i want to have a above csv in below format : headers --> CI Name CI Description CI Ref... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

9. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

10. Shell Programming and Scripting

Need to Insert three extra columns in csv file

Hello Experts, I got a requirement i have a input file which am getting from different source,Now i want to add extra 3 columns to this file like BASE,ACTUAL and DATE. Input File Looks like QUAL CHGE TYP LAW COM1 COM2 A 1 X SED HO ASE B 3 Z CDE SE ... (5 Replies)
Discussion started by: ahmed.vaghar
5 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 09:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy