Sponsored Content
Top Forums Shell Programming and Scripting Read in 2-column CSV, output many files based on field Post 302740137 by pxalpine on Wednesday 5th of December 2012 03:36:23 PM
Old 12-05-2012
Read in 2-column CSV, output many files based on field

Is there a way to read in a two-columned CSV file, and based on the fields in 1st column, output many different files? The input/output looks something like:

Code:
input.csv:
call	Call Mom.
call	Call T-Mobile.
go	Go home.
go	Go to school.
go	Go to gas station.
play	Play music.
play	Play Beatles.

Code:
outputs 3 files:
call.xml
<value><tokens><token>Call</token><token>Mom</token></tokens></value>
<value><tokens><token>Call</token><token>T-Mobile</token></tokens></value>

go.xml
<value><tokens><token>Go</token><token>home</token></tokens></value>
<value><tokens><token>Go</token><token>to</token><token>school</token></tokens></value>
<value><tokens><token>Go</token><token>to</token><token>gas</token><token>station</token></tokens></value>

play.xml
<value><tokens><token>Play</token><token>music</token></tokens></value>
<value><tokens><token>Play</token><token>Beatles</token></tokens></value>

I'm stuck at the part of checking which items in 1st column are the same, then saving all those identical items along with their rows into a new list?? Is this possible to do with shell scripts, or would I need to use Python?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read CSV column value based on column name

Hi All, I am newbie to Unix I ve got assignment to work in unix can you please help me in this regard There is a sample CSV file "Username", "Password" "John1", "Scot1" "John2", "Scot2" "John3", "Scot3" "John4", "Scot4" If i give the column name as Password and row number as 4 the... (3 Replies)
Discussion started by: JohnGG
3 Replies

2. Shell Programming and Scripting

extract data in a csv file based on a certain field.

I have a csv file that I need to extract some data from depending on another field after reading info from another text file. The text file would say have 592560 in it. The csv file may have some data like so Field 1 Field2 Field3 Field4 Field5 Field6 20009756 1 ... (9 Replies)
Discussion started by: GroveTuckey
9 Replies

3. Shell Programming and Scripting

Merging CSV fields based on a common field

Hi List, I have two files. File1 contains all of the data I require to be processed, and I need to add another field to this data by matching a common field in File2 and appending a corresponding field to the data in File1 based on the match... So: File 1:... (1 Reply)
Discussion started by: landossa
1 Replies

4. Shell Programming and Scripting

Matching and Merging csv data fields based on a common field

Dear List, I have a file of csv data which has a different line per compliance check per host. I do not want any omissions from this csv data file which looks like this: date,hostname,status,color,check 02-03-2012,COMP1,FAIL,Yellow,auth_pass_change... (3 Replies)
Discussion started by: landossa
3 Replies

5. Shell Programming and Scripting

awk read column csv and search in other csv

hi, someone to know how can i read a specific column of csv file and search the value in other csv columns if exist the value in the second csv copy entire row with all field in a new csv file. i suppose that its possible using awk but i m not expertise thanks in advance (8 Replies)
Discussion started by: giankan
8 Replies

6. Shell Programming and Scripting

Pick the column value based on another column from .csv file

My scenario is that I need to pick value from third column based on fourth column value, if fourth column value is 1 then first value of third column.Third column (2|3|4|6|1) values are cancatenated. Main imp point, in my .csv file, third column is having price value with comma (1,20,300), it has... (2 Replies)
Discussion started by: Ganesh L
2 Replies

7. Shell Programming and Scripting

Read text between regexps and write into files based on a field in the text

Hi, I have a huge file that has data something like shown below: huge_file.txt start regexp Name=Name1 Title=Analyst Address=Address1 Department=Finance end regexp some text some text start regexp Name=Name2 Title=Controller Address=Address2 Department=Finance end regexp (7 Replies)
Discussion started by: r3d3
7 Replies

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

9. Shell Programming and Scripting

Get maximum per column from CSV file, based on date column

Hello everyone, I am using ksh on Solaris 10 and I'm gathering data in a CSV file that looks like this: 20170628-23:25:01,1,0,0,1,1,1,1,55,55,1 20170628-23:30:01,1,0,0,1,1,1,1,56,56,1 20170628-23:35:00,1,0,0,1,1,2,1,57,57,2 20170628-23:40:00,1,0,0,1,1,1,1,58,58,2... (6 Replies)
Discussion started by: ejianu
6 Replies

10. UNIX for Beginners Questions & Answers

Select and copy .csv files based on row and column number

Dear UNIX experts, I'm a command line novice working on a Macintosh computer (Bash shell) and have neither found advice that is pertinent to my problem on the internet nor in this forum. I have hundreds of .csv files in a directory. Now I would like to copy the subset of files that contains... (8 Replies)
Discussion started by: rcsapo
8 Replies
PERF-DIFF(1)							    perf Manual 						      PERF-DIFF(1)

NAME
perf-diff - Read perf.data files and display the differential profile SYNOPSIS
perf diff [baseline file] [data file1] [[data file2] ... ] DESCRIPTION
This command displays the performance difference amongst two or more perf.data files captured via perf record. If no parameters are passed it will assume perf.data.old and perf.data. The differential profile is displayed only for events matching both specified perf.data files. OPTIONS
-D, --dump-raw-trace Dump raw trace in ASCII. -m, --modules Load module symbols. WARNING: use only with -k and LIVE kernel -d, --dsos= Only consider symbols in these dsos. CSV that understands file://filename entries. -C, --comms= Only consider symbols in these comms. CSV that understands file://filename entries. -S, --symbols= Only consider these symbols. CSV that understands file://filename entries. -s, --sort= Sort by key(s): pid, comm, dso, symbol. -t, --field-separator= Use a special separator character and don't pad with spaces, replacing all occurrences of this separator in symbol names (and other output) with a . character, that thus it's the only non valid separator. -v, --verbose Be verbose, for instance, show the raw counts in addition to the diff. -f, --force Don't complain, do it. --symfs=<directory> Look for files with symbols relative to this directory. -b, --baseline-only Show only items with match in baseline. -c, --compute Differential computation selection - delta,ratio,wdiff (default is delta). See COMPARISON METHODS section for more info. -p, --period Show period values for both compared hist entries. -F, --formula Show formula for given computation. -o, --order Specify compute sorting column number. COMPARISON
The comparison is governed by the baseline file. The baseline perf.data file is iterated for samples. All other perf.data files specified on the command line are searched for the baseline sample pair. If the pair is found, specified computation is made and result is displayed. All samples from non-baseline perf.data files, that do not match any baseline entry, are displayed with empty space within baseline column and possible computation results (delta) in their related column. Example files samples: - file A with samples f1, f2, f3, f4, f6 - file B with samples f2, f4, f5 - file C with samples f1, f2, f5 Example output: x - computation takes place for pair b - baseline sample percentage o perf diff A B C baseline/A compute/B compute/C samples --------------------------------------- b x f1 b x x f2 b f3 b x f4 b f6 x x f5 o perf diff B A C baseline/B compute/A compute/C samples --------------------------------------- b x x f2 b x f4 b x f5 x x f1 x f3 x f6 o perf diff C B A baseline/C compute/B compute/A samples --------------------------------------- b x f1 b x x f2 b x f5 x f3 x x f4 x f6 COMPARISON METHODS
delta If specified the Delta column is displayed with value d computed as: d = A->period_percent - B->period_percent with: - A/B being matching hist entry from data/baseline file specified (or perf.data/perf.data.old) respectively. o period_percent being the % of the hist entry period value within single data file ratio If specified the Ratio column is displayed with value r computed as: r = A->period / B->period with: - A/B being matching hist entry from data/baseline file specified (or perf.data/perf.data.old) respectively. o period being the hist entry period value wdiff:WEIGHT-B,WEIGHT-A If specified the Weighted diff column is displayed with value d computed as: d = B->period * WEIGHT-A - A->period * WEIGHT-B o A/B being matching hist entry from data/baseline file specified (or perf.data/perf.data.old) respectively. o period being the hist entry period value o WEIGHT-A/WEIGHT-B being user suplied weights in the the -c option behind : separator like -c wdiff:1,2. o WIEGHT-A being the weight of the data file o WIEGHT-B being the weight of the baseline data file SEE ALSO
perf-record(1) perf 06/30/2014 PERF-DIFF(1)
All times are GMT -4. The time now is 07:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy