Sponsored Content
Top Forums Shell Programming and Scripting Inserting new fields to a csv file Post 302847931 by midhun19 on Wednesday 28th of August 2013 05:18:56 AM
Old 08-28-2013
Quote:
Originally Posted by RudiC
Try (untested):
Code:
awk -F, '{$2=$2 FS "status,starttime"} 1' OFS="," file

i tried and got the result as

Code:
 
: awk -F, '{$2=$2 FS "status,starttime"} 1' test.dat
1 jobname1,status,starttime somthing somthing
2 jobname2,status,starttime somthing somthing
3 jobname3,status,starttime somthing somthing
4 jobname4,status,starttime somthing somthing

some comas are missing from the original file

---------- Post updated at 04:18 AM ---------- Previous update was at 04:15 AM ----------

Quote:
Originally Posted by midhun19
i tried and got the result as

Code:
 
: awk -F, '{$2=$2 FS "status,starttime"} 1' test.dat
1 jobname1,status,starttime somthing somthing
2 jobname2,status,starttime somthing somthing
3 jobname3,status,starttime somthing somthing
4 jobname4,status,starttime somthing somthing

some comas are missing from the original file

I think i missed OFS="," from the first post. Now I'm able to get the result as intended.

Thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to work with fields of a csv file?

I need to insert data into a perticular field of a csv file, lets say second field. Can any one help me to do this? I found that we can do it with sed. can any one guide me to accomplish this? thanks in advance. (12 Replies)
Discussion started by: praveen_b744
12 Replies

2. Shell Programming and Scripting

How to create a CSV File by reading fields from separate files

SHELL SCRIPT Hi, I have 3 separate files within a folder. Every File contains data in a single column like File1 contains data mayank sushant dheeraj File2 contains DSA_AT MG_AT FLAT_09 File3 contains data 123123 232323 (2 Replies)
Discussion started by: mayanksargoch
2 Replies

3. Shell Programming and Scripting

pulling different fields from a csv file

Hi, I have a requirment where I need to pull different columns from a .csv file. Here is the sample of the csv file. account,item,flag1,flag2,flag3,flag4,flag5,......feed,tran I will be have a config.txt file which will have the following information. item,flag5,flag10,feed,tran... (2 Replies)
Discussion started by: akdevula
2 Replies

4. Shell Programming and Scripting

Comparing two csv file fields using awk script

Hi All, I want to remove the rows from File1.csv by comparing the columns/fields in the File2.csv. I only need the records whose first column is same and the second column is different for the same record in both files.Here is an example on what I need. File1.csv: RAJAK|ACTIVE|1... (2 Replies)
Discussion started by: rajak.net
2 Replies

5. Shell Programming and Scripting

Inserting additional comma delimiters in a csv file, after and before certian fields.

Hello I have a csv file which I need to insert addtional commas into. The csv is of the format field1,field2,field3,field4,...etc...,field13,field14 I need to add extra commas in each record so that the final output looks like ... (1 Reply)
Discussion started by: kamal_p_99
1 Replies

6. Shell Programming and Scripting

Randomly inserting extra columns into csv file

Hi Tech Guru, I have a test file as below , which needs some more fields to be populated randomly : 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 ... (8 Replies)
Discussion started by: Lokesha
8 Replies

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

8. Emergency UNIX and Linux Support

How to convert the following characters in some fields in a csv file?

I have a csv file which is produced out of a SED command sed 's/|/","/g; s/^/"/; s/$/"/' A4.txt > A5.csv and I need either an addition to the SED command or a separate command to convert the following characters which occur within the fields in multiple lines 1) "=" to =" and 2)""~ to " (4 Replies)
Discussion started by: etldev
4 Replies

9. UNIX for Beginners Questions & Answers

How to count lines of CSV file where 2 fields match variables?

I'm trying to use awk to count the occurrences of two matching fields of a CSV file. For instance, for data that looks like this... Joe,Blue,Yes,No,High Mike,Blue,Yes,Yes,Low Joe,Red,No,No,Low Joe,Red,Yes,Yes,Low I've been trying to use code like this... countvar=`awk ' $2~/$color/... (4 Replies)
Discussion started by: nmoore2843
4 Replies

10. Shell Programming and Scripting

Matching two fields in two csv files, create new file and append match

I am trying to parse two csv files and make a match in one column then print the entire file to a new file and append an additional column that gives description from the match to the new file. If a match is not made, I would like to add "NA" to the end of the file Command that Ive been using... (6 Replies)
Discussion started by: dis0wned
6 Replies
MIDI::Score(3)						User Contributed Perl Documentation					    MIDI::Score(3)

NAME
MIDI::Score - MIDI scores SYNOPSIS
# it's a long story; see below DESCRIPTION
This module provides functions to do with with MIDI scores. It is used as the basis for all the functions in MIDI::Simple. (Incidentally, MIDI::Opus's draw() method also uses some of the functions in here.) Whereas the events in a MIDI event structure are items whose timing is expressed in delta-times, the timing of items in a score is expressed as an absolute number of ticks from the track's start time. Moreover, pairs of 'note_on' and 'note_off' events in an event structure are abstracted into a single 'note' item in a score structure. 'note' takes the following form: ('note_on', I<start_time>, I<duration>, I<channel>, I<note>, I<velocity>) The problem that score structures are meant to solve is that 1) people definitely don't think in delta-times -- they think in absolute times or in structures based on that (like 'time from start of measure'); 2) people think in notes, not note_on and note_off events. So, given this event structure: ['text_event', 0, 'www.ely.anglican.org/parishes/camgsm/chimes.html'], ['text_event', 0, 'Lord through this hour/ be Thou our guide'], ['text_event', 0, 'so, by Thy power/ no foot shall slide'], ['patch_change', 0, 1, 8], ['note_on', 0, 1, 25, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 29, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 27, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 20, 96], ['note_off', 192, 0, 1, 0], ['note_on', 0, 1, 25, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 27, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 29, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 25, 96], ['note_off', 192, 0, 1, 0], ['note_on', 0, 1, 29, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 25, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 27, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 20, 96], ['note_off', 192, 0, 1, 0], ['note_on', 0, 1, 20, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 27, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 29, 96], ['note_off', 96, 0, 1, 0], ['note_on', 0, 1, 25, 96], ['note_off', 192, 0, 1, 0], here is the corresponding score sctructure: ['text_event', 0, 'www.ely.anglican.org/parishes/camgsm/chimes.html'], ['text_event', 0, 'Lord through this hour/ be Thou our guide'], ['text_event', 0, 'so, by Thy power/ no foot shall slide'], ['patch_change', 0, 1, 8], ['note', 0, 96, 1, 25, 96], ['note', 96, 96, 1, 29, 96], ['note', 192, 96, 1, 27, 96], ['note', 288, 192, 1, 20, 96], ['note', 480, 96, 1, 25, 96], ['note', 576, 96, 1, 27, 96], ['note', 672, 96, 1, 29, 96], ['note', 768, 192, 1, 25, 96], ['note', 960, 96, 1, 29, 96], ['note', 1056, 96, 1, 25, 96], ['note', 1152, 96, 1, 27, 96], ['note', 1248, 192, 1, 20, 96], ['note', 1440, 96, 1, 20, 96], ['note', 1536, 96, 1, 27, 96], ['note', 1632, 96, 1, 29, 96], ['note', 1728, 192, 1, 25, 96] Note also that scores aren't crucially ordered. So this: ['note', 768, 192, 1, 25, 96], ['note', 960, 96, 1, 29, 96], ['note', 1056, 96, 1, 25, 96], means the same thing as: ['note', 960, 96, 1, 29, 96], ['note', 768, 192, 1, 25, 96], ['note', 1056, 96, 1, 25, 96], The only exception to this is in the case of things like: ['patch_change', 200, 2, 15], ['note', 200, 96, 2, 25, 96], where two (or more) score items happen at the same time and where one affects the meaning of the other. WHAT CAN BE IN A SCORE
Besides the new score structure item "note" (covered above), the possible contents of a score structure can be summarized thus: Whatever can appear in an event structure can appear in a score structure, save that its second parameter denotes not a delta-time in ticks, but instead denotes the absolute number of ticks from the start of the track. To avoid the long periphrase "items in a score structure", I will occasionally refer to items in a score structure as "notes", whether or not they are actually "note" commands. This leaves "event" to unambiguously denote items in an event structure. These, below, are all the items that can appear in a score. This is basically just a repetition of the table in MIDI::Event, with start- time substituting for dtime -- so refer to MIDI::Event for an explanation of what the data types (like "velocity" or "pitch_wheel"). As far as order, the first items are generally the most important: ('note', starttime, duration, channel, note, velocity) ('key_after_touch', starttime, channel, note, velocity) ('control_change', starttime, channel, controller(0-127), value(0-127)) ('patch_change', starttime, channel, patch) ('channel_after_touch', starttime, channel, velocity) ('pitch_wheel_change', starttime, channel, pitch_wheel) ('set_sequence_number', starttime, sequence) ('text_event', starttime, text) ('copyright_text_event', starttime, text) ('track_name', starttime, text) ('instrument_name', starttime, text) ('lyric', starttime, text) ('marker', starttime, text) ('cue_point', starttime, text) ('text_event_08', starttime, text) ('text_event_09', starttime, text) ('text_event_0a', starttime, text) ('text_event_0b', starttime, text) ('text_event_0c', starttime, text) ('text_event_0d', starttime, text) ('text_event_0e', starttime, text) ('text_event_0f', starttime, text) ('end_track', starttime) ('set_tempo', starttime, tempo) ('smpte_offset', starttime, hr, mn, se, fr, ff) ('time_signature', starttime, nn, dd, cc, bb) ('key_signature', starttime, sf, mi) ('sequencer_specific', starttime, raw) ('raw_meta_event', starttime, command(0-255), raw) ('sysex_f0', starttime, raw) ('sysex_f7', starttime, raw) ('song_position', starttime) ('song_select', starttime, song_number) ('tune_request', starttime) ('raw_data', starttime, raw) FUNCTIONS
This module provides these functions: $score2_r = MIDI::Score::copy_structure($score_r) This takes a reference to a score structure, and returns a reference to a copy of it. Example usage: @new_score = @{ MIDI::Score::copy_structure( @old_score ) }; $events_r = MIDI::Score::score_r_to_events_r( $score_r ) ($events_r, $ticks) = MIDI::Score::score_r_to_events_r( $score_r ) This takes a reference to a score structure, and converts it to an event structure, which it returns a reference to. In list context, also returns a second value, a count of the number of ticks that structure takes to play (i.e., the end-time of the temporally last item). $score2_r = MIDI::Score::sort_score_r( $score_r) This takes a reference to a score structure, and returns a reference to a sorted (by time) copy of it. Example usage: @sorted_score = @{ MIDI::Score::sort_score_r( @old_score ) }; $score_r = MIDI::Score::events_r_to_score_r( $events_r ) ($score_r, $ticks) = MIDI::Score::events_r_to_score_r( $events_r ) This takes a reference to an event structure, converts it to a score structure, which it returns a reference to. If called in list context, also returns a count of the number of ticks that structure takes to play (i.e., the end-time of the temporally last item). $ticks = MIDI::Score::score_r_time( $score_r ) This takes a reference to a score structure, and returns a count of the number of ticks that structure takes to play (i.e., the end- time of the temporally last item). MIDI::Score::dump_score( $score_r ) This dumps (via "print") a text representation of the contents of the event structure you pass a reference to. COPYRIGHT
Copyright (c) 1998-2002 Sean M. Burke. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHOR
Sean M. Burke "sburke@cpan.org" perl v5.8.0 2002-11-16 MIDI::Score(3)
All times are GMT -4. The time now is 03:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy