Sponsored Content
Full Discussion: Re-order columns
Top Forums Shell Programming and Scripting Re-order columns Post 302928307 by cmccabe on Wednesday 10th of December 2014 05:38:27 PM
Old 12-10-2014
Code:
 awk 'BEGIN{OFS=FS=","}NR==FNR{a[ $11 <> "unknown"];next} in a{print $4,$11,$7,$13}' test.txt > newfile.txt


Thank you Smilie.

Last edited by cmccabe; 12-10-2014 at 06:48 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Changing the order of columns in a script

I have the following script: (echo -n `curl http://www.example.com/scores.txt | grep mylocation`; date +%Y%m%d%H%M%S) >> myscores.txt This script works fine, except that it places the timestamp at the end of the file myscores.txt. How do add the timestamp as the first column and then a tab and... (4 Replies)
Discussion started by: figaro
4 Replies

2. Shell Programming and Scripting

Change many columns position/order

Hi everyone, Please some help over here. (I´m using cygwing) I have files with 40 columns and 2000 lines in average. I´m trying to change the order position as follow. Original columns position:... (3 Replies)
Discussion started by: cgkmal
3 Replies

3. Shell Programming and Scripting

Single command for add 2 columns and remove 2 columns in unix/performance tuning

Hi all, I have created a script which adding two columns and removing two columns for all files. Filename: Cust_information_1200_201010.txt Source Data: "1","Cust information","123","106001","street","1-203 high street" "1","Cust information","124","105001","street","1-203 high street" ... (0 Replies)
Discussion started by: onesuri
0 Replies

4. UNIX for Advanced & Expert Users

Help in Deleting columns and Renaming Mutliple columns in a .Csv File

Hi All, i have a .Csv file in the below format startTime, endTime, delta, gName, rName, rNumber, m2239max, m2239min, m2239avg, m100016509avg, m100019240max, metric3min, m100019240avg, propValues 11-Mar-2012 00:00:00, 11-Mar-2012 00:05:00, 300.0, vma3550a, a-1_CPU Index<1>, 200237463, 0.0,... (9 Replies)
Discussion started by: mahi_mayu069
9 Replies

5. Shell Programming and Scripting

Combine columns from many files but keep them aligned in columns-shorter left column issue

Hello everyone, I searched the forum looking for answers to this but I could not pinpoint exactly what I need as I keep having trouble. I have many files each having two columns and hundreds of rows. first column is a string (can have many words) and the second column is a number.The files are... (5 Replies)
Discussion started by: isildur1234
5 Replies

6. Shell Programming and Scripting

Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks

Hi Friends, I have come across some files where some of the columns don not have data. Key, Data1,Data2,Data3,Data4,Data5 A,5,6,,10,, A,3,4,,3,, B,1,,4,5,, B,2,,3,4,, If we see the above data on Data5 column do not have any row got filled. So remove only that column(Here Data5) and... (4 Replies)
Discussion started by: ks_reddy
4 Replies

7. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

8. Shell Programming and Scripting

CSv2dat file headers and columns order

Dear all, I have a csv file which is transformed to .dat. I have an awk file which is supposing to do the mapping of the dat file. the code from the awk file is the one below. The content of the dat file is looking like this (tab separated): ODT AGE CDT CO SEX TIME ... (9 Replies)
Discussion started by: grikoss
9 Replies

9. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

10. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns satisfy the condition

HI All, I'm embedding SQL query in Script which gives following output: Assignee Group Total ABC Group1 17 PQR Group2 5 PQR Group3 6 XYZ Group1 10 XYZ Group3 5 I have saved the above output in a file. How do i sum up the contents of this output so as to get following output: ... (4 Replies)
Discussion started by: Khushbu
4 Replies
funcolumnactivate(3)						SAORD Documentation					      funcolumnactivate(3)

NAME
FunColumnActivate - activate Funtools columns SYNOPSIS
#include <funtools.h> void FunColumnActivate(Fun fun, char *s, char *plist) DESCRIPTION
The FunColumnActivate() routine determines which columns (set up by FunColumnSelect()) ultimately will be read and/or written. By default, all columns that are selected using FunColumnSelect() are activated. The FunColumnActivate() routine can be used to turn off/off activa- tion of specific columns. The first argument is the Fun handle associated with this set of columns. The second argument is a space-delimited list of columns to activate or de-activate. Columns preceded by "+" are activated and columns preceded by a "-" are de-activated. If a column is named with- out "+" or "-", it is activated. The reserved strings "$region" and '$n' are used to activate a special columns containing the filter region value and row value, respectively, associated with this row. For example, if a filter containing two circular regions is specified as part of the Funtools file name, this column will contain a value of 1 or 2, depending on which region that row was in. The reserved strings "$x" and "$y" are used to activate the current binning columns. Thus, if the columns DX and DY are specified as binning columns: [sh $] fundisp foo.fits[bincols=(DX,DY)] then "$x" and "$y" will refer to these columns in a call to FunColumnActivate(). In addition, if the activation string contains only columns to be activated, then the routine will de-activate all other columns. Simi- larly, if the activation string contains only columns to de-activate, then the routine will activate all other columns before activating the list. This makes it simple to change the activation state of all columns without having to know all of the column names. For example: o "pi pha time" # only these three columns will be active o "-pi -pha -time" # all but these columns will be active o "pi -pha" # only pi is active, pha is not, others are not o "+pi -pha" # same as above o "pi -pha -time" # only pi is active, all others are not o "pi pha" # pha and pi are active, all others are not o "pi pha -x -y" # pha and pi are active, all others are not You can use the column activation list to reorder columns, since columns are output in the order specified. For example: # default output order fundisp snr.ev'[cir 512 512 .1]' X Y PHA PI TIME DX DY -------- -------- -------- -------- --------------------- -------- -------- 512 512 6 7 79493997.45854475 578 574 512 512 8 9 79494575.58943175 579 573 512 512 5 6 79493631.03866175 578 575 512 512 5 5 79493290.86521725 578 575 512 512 8 9 79493432.00990875 579 573 # re-order the output by specifying explicit order fundisp snr.ev'[cir 512 512 .1]' "time x y dy dx pi pha" TIME X Y DY DX PI PHA --------------------- -------- -------- -------- -------- -------- -------- 79493997.45854475 512 512 574 578 7 6 79494575.58943175 512 512 573 579 9 8 79493631.03866175 512 512 575 578 6 5 79493290.86521725 512 512 575 578 5 5 79493432.00990875 512 512 573 579 9 8 A "+" sign by itself means to activate all columns, so that you can reorder just a few columns without specifying all of them: # reorder 3 columns and then output the rest fundisp snr.ev'[cir 512 512 .1]' "time pi pha +" TIME PI PHA Y X DX DY --------------------- -------- -------- -------- -------- -------- -------- 79493997.45854475 7 6 512 512 578 574 79494575.58943175 9 8 512 512 579 573 79493631.03866175 6 5 512 512 578 575 79493290.86521725 5 5 512 512 578 575 79493432.00990875 9 8 512 512 579 573 The column activation/deactivation is performed in the order of the specified column arguments. This means you can mix "+", "-" (which de- activates all columns) and specific column names to reorder and select columns in one command. For example, consider the following: # reorder and de-activate fundisp snr.ev'[cir 512 512 .1]' "time pi pha + -x -y" TIME PI PHA DX DY --------------------- -------- -------- -------- -------- 79493997.45854475 7 6 578 574 79494575.58943175 9 8 579 573 79493631.03866175 6 5 578 575 79493290.86521725 5 5 578 575 79493432.00990875 9 8 579 573 We first activate "time", "pi", and "pha" so that they are output first. We then activate all of the other columns, and then de-activate "x" and "y". Note that this is different from: # probably not what you want ... fundisp snr.ev'[cir 512 512 .1]' "time pi pha -x -y +" TIME PI PHA Y X DX DY --------------------- -------- -------- -------- -------- -------- -------- 79493997.45854475 7 6 512 512 578 574 79494575.58943175 9 8 512 512 579 573 79493631.03866175 6 5 512 512 578 575 79493290.86521725 5 5 512 512 578 575 79493432.00990875 9 8 512 512 579 573 Here, "x" and "y" are de-activated, but then all columns including "x" and "y" are again re-activated. Typically, FunColumnActivate() uses a list of columns that are passed into the program from the command line. For example, the code for funtable contains the following: char *cols=NULL; /* open the input FITS file */ if( !(fun = FunOpen(argv[1], "rc", NULL)) ) gerror(stderr, "could not FunOpen input file: %s ", argv[1]); /* set active flag for specified columns */ if( argc >= 4 ) cols = argv[3]; FunColumnActivate(fun, cols, NULL); The FunOpen() call sets the default columns to be all columns in the input file. The FunColumnActivate() call then allows the user to con- trol which columns ultimately will be activated (i.e., in this case, written to the new file). For example: funtable test.ev foo.ev "pi pha time" will process only the three columns mentioned, while: funtable test.ev foo.ev "-time" will process all columns except "time". If FunColumnActivate() is called with a null string, then the environment variable FUN_COLUMNS will be used to provide a global value, if present. This is the reason why we call the routine even if no columns are specified on the command line (see example above), instead of calling it this way: /* set active flag for specified columns */ if( argc >= 4 ){ FunColumnActivate(fun, argv[3], NULL); } SEE ALSO
See funtools(7) for a list of Funtools help pages version 1.4.2 January 2, 2008 funcolumnactivate(3)
All times are GMT -4. The time now is 04:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy