Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Pivoting data based on a header field Post 303032445 by Scrutinizer on Monday 18th of March 2019 12:17:42 PM
Old 03-18-2019
Hi you can try adapting the following approach to your needs:


Code:
$ awk 'NR==1{n=split($0,H); next} {for(i=2;i<=NF;i++) print $1,H[i],$i}' FS=, OFS=, file
0050,001, 
0050,001f,0
0050,002, 
0050,002f,0
0050,003, 
0050,003f,0
0050,004, 
0050,004f,1
0050,005,*
0050,005f,7
0050,006, 
0050,006f,7
0050,007, 
0050,007f,7
0060,001, 
0060,001f,0
0060,002, 
0060,002f,0
0060,003, 
0060,003f,7
0060,004, 
0060,004f,0
0060,005,*
0060,005f,7
0060,006, 
0060,006f,0
0060,007, 
0060,007f,0


Last edited by Scrutinizer; 03-18-2019 at 03:27 PM..
This User Gave Thanks to Scrutinizer For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

generating reports based on time field of network data

hi i have data extracted in the following format ranging around 300000 to 800000 records in a text file , the format is of network data . No. Time Source Destination Protocol 1 1998-06-05 17:20:23.569905 HP_61:aa:c9 HP_61:aa:c9 ... (1 Reply)
Discussion started by: renukaprasadb
1 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. UNIX for Dummies Questions & Answers

Sorting data in file based on field in another file

Hi, I have two files, one of which I would like to sort based on the order of the data in the second. I would like to do this using a simple unix statement. My two files as follows: File 1: 12345 1 2 2 2 0 0 12349 0 0 2 2 1 2 12350 1 2 1 2 2 2 . . . File2: 12350... (3 Replies)
Discussion started by: kasan0
3 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

Pivoting the data

Hello Unix guys, I have the following 4 column data, which is a output of db2 select query: Need to pivot the data. sample Input: Year Month Country Counts 2012 Aug Canada 114 2012 Aug USA 92 2012 Aug Mexico 3 2012 Aug ... (3 Replies)
Discussion started by: karumudi7
3 Replies

6. Shell Programming and Scripting

awk : Filter a set of data to parse header line and last field of multiple same match.

Hi Experts, I have a data with multiple entry , I want to filter PKG= & the last column "00060110" or "00088150" in the output file: ############################################################################################### PKG= P8SDB :: VGS = vgP8SOra vgP8SDB1 vgP8S001... (5 Replies)
Discussion started by: rveri
5 Replies

7. Shell Programming and Scripting

Pivoting csv field from pipe delimited file

Hello All, Thanks for taking time to read through the thread and for providing any possible solution. I am trying to pivot a comma separated field in a pipe delimited file. Data looks something like this: Field1|Field2 123|345,567,789 234|563,560 345|975,098,985,397,984 456|736 Desired... (8 Replies)
Discussion started by: svks1985
8 Replies

8. Linux

Pivoting data with awk

Hi Friends, I need to pivot data . Below is my source data Source Data PK PRTY_KEY_ID PRTY_SUB_KEY_ID KEY_COL_VAL_TX MTCH_CNFDNCE_RATE 007824822 428844791 1 #Jemmy#Pom#600 Kearsarge Way 100 007824822 429283974 1 #Jemmy#Pom#120 Broadway 100 007824822 429739103 1 #Jemmy#Pom#600 Keae Way#757... (0 Replies)
Discussion started by: patiljeevan3
0 Replies

9. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies
JIRB1.3(1)						      General Commands Manual							JIRB1.3(1)

NAME
jirb1.3 - interactive JRuby SYNOPSIS
jirb [options] DESCRIPTION
irb stands for `interactive JRuby'. irb is a tool to execute interactively JRuby expressions read from stdin. Use of jirb is easy if you know JRuby. Executing jirb, prompts are displayed as follows. Then, enter expression of ruby. A input is executed when it is syntacticaly completed. $ jirb1.3 irb(main):001:0> 1+2 3 irb(main):002:0> class Foo irb(main):003:1> def foo irb(main):004:2> print 1 irb(main):005:2> end irb(main):006:1> end nil irb(main):007:0> And, Readline extesion module can be used with irb. Using Readline is the standard default action if Readline is installed. OPTIONS
-f suppress read ~/.irbrc -m bc mode (fraction or matrix are available) -d set $DEBUG to true (same as `ruby -d') -r load-module same as `ruby -r' --inspect uses `inspect' for output (the default except bc mode) --noinspect doesn't uses inspect for output --readline uses Readline extension module --noreadline doesn't use Readline extension module --prompt prompt-mode --prompt-mode prompt-mode switches prompt mode. Pre-defined prompt modes are `default', `simple', `xmp' and `inf-ruby' --inf-ruby-mode uses prompt appreciate for inf-ruby-mode on emacs. Suppresses --readline. --simple-prompt simple prompt mode --noprompt no prompt --tracer display trace for each execution of commands. --back-trace-limit n displayes backtrace top n and tail n. The default value is 16. --irb_debug n sets internal debug level to n (It shouldn't be used) -v, --version prints the version of irb CONFIGURATIONS
jirb reads `~/.irbrc' when it is invoked. If `~/.irbrb' doesn't exist jirb try to read in the order `.irbrc', `irb.rc', `_irbrc' then `$irbrc'. The following is altanative to the command line option. To use them type as follows in a jirb session. IRB.conf[:IRB_NAME]="irb" IRB.conf[:MATH_MODE]=false IRB.conf[:USE_TRACER]=false IRB.conf[:USE_LOADER]=false IRB.conf[:IGNORE_SIGINT]=true IRB.conf[:IGNORE_EOF]=false IRB.conf[:INSPECT_MODE]=nil IRB.conf[:IRB_RC] = nil IRB.conf[:BACK_TRACE_LIMIT]=16 IRB.conf[:USE_LOADER] = false IRB.conf[:USE_READLINE] = nil IRB.conf[:USE_TRACER] = false IRB.conf[:IGNORE_SIGINT] = true IRB.conf[:IGNORE_EOF] = false IRB.conf[:PROMPT_MODE] = :DEFALUT IRB.conf[:PROMPT] = {...} IRB.conf[:DEBUG_LEVEL]=0 IRB.conf[:VERBOSE]=true Customizing prompt To costomize the prompt you set a variable IRB.conf[:PROMPT] For example, describe as follows in `.irbrc'. IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode :PROMPT_I => nil, # normal prompt :PROMPT_S => nil, # prompt for continuated strings :PROMPT_C => nil, # prompt for continuated statement :RETURN => " ==>%s " # format to return value } Then, invoke irb with the above prompt mode by $ jirb1.3 --prompt my-prompt Or add the following in `.irbrc'. IRB.conf[:PROMPT_MODE] = :MY_PROMPT Constants PROMPT_I, PROMPT_S and PROMPT_C specifies the format. In the prompt specification, some special strings are available. %N command name which is running %m to_s of main object (self) %M inspect of main object (self) %l type of string(", ', /, ]), `]' is inner %w[...] %NNi indent level. NN is degits and means as same as printf("%NNd"). It can be ommited %NNn line number. %% % For instance, the default prompt mode is defined as follows: IRB.conf[:PROMPT_MODE][:DEFAULT] = { PROMPT_I => "%N(%m):%03n:%i> ", PROMPT_S => "%N(%m):%03n:%i%l ", PROMPT_C => "%N(%m):%03n:%i* ", RETURN => "%s "} RETURN is used to printf. Configurating subirb The command line option or IRB.conf specify the default behavior of (sub)irb. On the other hand, each conf of in the next sction `6. Com- mand' is used to individually configurate (sub)irb. If proc is set to IRB.conf[:IRB_RC], its subirb will be invoked after execution of that proc under giving the context of irb as its aregument. By this mechanism each subirb can be configurated. Command For irb commands, both simple name and `irb_'-prefixed name are prepared. exit, quit, irb_exit Quits (sub)irb. if you've done cb (see below), exit from the binding mode. conf, irb_context Displays current configuration. Modifing the configuration is achieved by sending message to `conf'. conf.back_trace_limit Sets display lines of backtrace as top n and tail n. The default value is 16. conf.debug_level = N Sets debug level of irb. conf.ignore_eof = true/false Whether ^D (control-d) will be ignored or not. If false is set, ^D means quit. conf.ignore_sigint= true/false Whether ^C (control-c) will be ignored or not. If false is set, ^D means quit. If true, during input: cancel inputing then return to top level. during execute: abondon current execution. conf.inf_ruby_mode = true/false Whether inf-ruby-mode or not. The default value is false. conf.inspect_mode = true/false/nil Specifies inspect mode. true: display inspect false: display to_s nil: inspect mode in non math mode, non inspect mode in math mode. conf.irb_level The level of cb. conf.math_mode Whether bc mode or not. conf.use_loader = true/false Whether irb's own file reader method is used when load/require or not. This mode is globaly affected (irb wide). conf.prompt_c prompt for a continuating statement (e.g, immediately after of `if') conf.prompt_i standard prompt conf.prompt_s prompt for a continuating string conf.rc Whether ~/.irbrc is read or not. conf.use_prompt = true/false Prompting or not. conf.use_readline = true/false/nil Whether readline is used or not. true: uses false: doen't use nil: intends to use readline except for inf-reuby-mode (default) conf.verbose=T/F Whether verbose messages are display or not. cb, irb_change_binding [obj] Enter new binding which has a distinct scope of local variables. If obj is given, obj will be self. irb [obj] Invoke subirb. If obj is given, obj will be self. jobs, irb_jobs List of subirb fg n, irb_fg n Switch into specified subirb. The following is candidates of n: irb number thhread irb object self(obj which is specified of irb obj) kill n, irb_kill n Kill subirb. The means of n is as same as the case of irb_fg. System variable _ The latest value of evaluation (it is local) Session Example $ jirb1.3 irb(main):001:0> irb # invoke subirb irb#1(main):001:0> jobs # list of subirbs #0->irb on main (#<Thread:0x400fb7e4> : stop) #1->irb#1 on main (#<Thread:0x40125d64> : running) nil irb#1(main):002:0> fg 0 # switch job nil irb(main):002:0> class Foo;end nil irb(main):003:0> irb Foo # invoke subirb which has the # context of Foo irb#2(Foo):001:0> def foo # define Foo#foo irb#2(Foo):002:1> print 1 irb#2(Foo):003:1> end nil irb#2(Foo):004:0> fg 0 # switch job nil irb(main):004:0> jobs # list of job #0->irb on main (#<Thread:0x400fb7e4> : running) #1->irb#1 on main (#<Thread:0x40125d64> : stop) #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop) nil irb(main):005:0> Foo.instance_methods # Foo#foo is defined asurely ["foo"] irb(main):006:0> fg 2 # switch job nil irb#2(Foo):005:0> def bar # define Foo#bar irb#2(Foo):006:1> print "bar" irb#2(Foo):007:1> end nil irb#2(Foo):010:0> Foo.instance_methods ["bar", "foo"] irb#2(Foo):011:0> fg 0 nil irb(main):007:0> f = Foo.new #<Foo:0x4010af3c> irb(main):008:0> irb f # invoke subirb which has the # context of f (instance of Foo) irb#3(#<Foo:0x4010af3c>):001:0> jobs #0->irb on main (#<Thread:0x400fb7e4> : stop) #1->irb#1 on main (#<Thread:0x40125d64> : stop) #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop) #3->irb#3 on #<Foo:0x4010af3c> (#<Thread:0x4010a1e0> : running) nil irb#3(#<Foo:0x4010af3c>):002:0> foo # evaluate f.foo 1nil irb#3(#<Foo:0x4010af3c>):003:0> bar # evaluate f.bar barnil irb#3(#<Foo:0x4010af3c>):004:0> kill 1, 2, 3# kill job nil irb(main):009:0> jobs #0->irb on main (#<Thread:0x400fb7e4> : running) nil irb(main):010:0> exit # exit Restrictions Because irb evaluates the inputs immediately after the imput is syntactically completed, irb gives slight different result than directly use ruby. Known difference is pointed out here. Declaration of the local variable The following causes an error in ruby: eval "foo = 0" foo -- -:2: undefined local variable or method `foo' for #<Object:0x40283118> (NameError) --- NameError Though, the above will successfully done by irb. >> eval "foo = 0" => 0 >> foo => 0 Ruby evaluates a code after reading entire of code and determination of the scope of local variables. On the other hand, irb do immedi- ately. More precisely, irb evaluate at first evel "foo = 0" then foo is defined on this timing. It is because of this incompatibility. If you'd like to detect those differences, begin...end can be used: >> begin ?> eval "foo = 0" >> foo >> end NameError: undefined local variable or method `foo' for #<Object:0x4013d0f0> (irb):3 (irb_local_binding):1:in `eval' Here-document Implementation of Here-document is incomplete. Symbol Irb can not always recognize a symbol as to be Symbol. Concretely, an expression have completed, however Irb regard it as continuation line. April 2007 JIRB1.3(1)
All times are GMT -4. The time now is 03:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy