Sponsored Content
Top Forums Shell Programming and Scripting Make copy of text file with columns removed (based on header) Post 302931578 by LMHmedchem on Wednesday 14th of January 2015 01:31:21 AM
Old 01-14-2015
Make copy of text file with columns removed (based on header)

Hello,

I have some tab delimited text files with a three header rows. The headers look like, (sorry the tabs look so messy).

Code:
index	group	Name	input	input	input	input	input	input	input	input	input	input	input
int	char	string	double	double	double	double	double	double	double	double	double	double	double
id	group	Name	AtR_Ptb_L	flatness	inv_dx2	rvalHyd	sumLip	xv0	dxv1	Gmax	k2	Spyridin_N	Salph_N

The files could have any number of columns. What I need to do is simple. I just need to copy the file with one or more columns removed. The columns to be removed would be specified by the value in the third row. For example, I could want the files with columns "dxv1" and "k2" removed.
Code:
index	group	Name	input	input	input	input	input	input	input	input	input
int	char	string	double	double	double	double	double	double	double	double	double
id	group	Name	AtR_Ptb_L	flatness	inv_dx2	rvalHyd	sumLip	xv0	Gmax	Spyridin_N	Salph_N

The order of the remaining columns should be the same. It doesn't matter how the list of columns to be removed is formatted. It can be any kind of list.

I have read posts about how to copy specific columns with cut or awk, but not how to skip specific cols and copy everything else. One thing to do would be to find the position of the cols to be removed and use cut, but how to set that up to work in a general implementation is a bit unclear to me. I also suspect that awk would be more efficient.

Any suggestions?

LMHmedchem
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Merging two files based on two columns to make a third file

Hi there, I'm trying to merge two files and make a third file. However, two of the columns need to match exactly in both files AND I want everything from both files in the output if the two columns match in that row. First file looks like this: chr1 10001980 T A Second... (12 Replies)
Discussion started by: infiniteabyss
12 Replies

2. Shell Programming and Scripting

Copy and Paste Columns in a Tab-Limited Text file

I have this text file with a very large number of columns (10,000+) and I want to move the first column to the position of the six column so that the text file looks like this: Before cutting and pasting ID Family Mother Father Trait Phenotype aaa bbb ... (5 Replies)
Discussion started by: evelibertine
5 Replies

3. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the values of two columns (given ranges)

Hi, I have a tab delimited text file with multiple columns. The second and third columns include numbers that have not been sorted. I want to extract rows where the second column includes a value between -0.01 and 0.01 (including both numbers) and the first third column includes a value between... (1 Reply)
Discussion started by: evelibertine
1 Replies

4. Shell Programming and Scripting

Reading columns from a text file and to make an array for each column

Hi, I am not so familiar with bash scripting and would appreciate your help here. I have a text file 'input.txt' like this: 2 3 4 5 6 7 8 9 10 I want to store each column in an array like this a ={2 5 8}, b={3 6 9}, c={4 7 10} so that i can access any element, e.g b=6 for the later use. (1 Reply)
Discussion started by: Asif Siddique
1 Replies

5. Shell Programming and Scripting

Extract columns based on header

Hi to all, I have two files. File1 has no header, two columns: sample1 A sample2 B sample3 B sample4 C sample5 A sample6 D sample7 D File2 has a header, except for the first 3 columns (chr,start,end). "sample1" is the header for the 4th ,5th ,6th columns, "sample2" is the header... (4 Replies)
Discussion started by: aec
4 Replies

6. Emergency UNIX and Linux Support

Average columns based on header name

Hi Friends, I have files with columns like this. This sample input below is partial. Please check below for main file link. Each file will have only two rows. ... (8 Replies)
Discussion started by: jacobs.smith
8 Replies

7. UNIX for Beginners Questions & Answers

Keep only columns in first two rows based on partial header pattern.

I have this code below that only prints out certain columns from the first two rows (doesn't affect rows 3 and beyond). How can I do the same on a partial header pattern “G_TP” instead of having to know specific column numbers (e.g. 374-479)? I've tried many other commands within this pipe with no... (4 Replies)
Discussion started by: aachave1
4 Replies

8. Shell Programming and Scripting

Find columns in a file based on header and print to new file

Hello, I have to fish out some specific columns from a file based on the header value. I have the list of columns I need in a different file. I thought I could read in the list of headers I need, # file with header names of required columns in required order headers_file=$2 # read contents... (11 Replies)
Discussion started by: LMHmedchem
11 Replies

9. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies
LEGENDRE(3)						User Contributed Perl Documentation					       LEGENDRE(3)

NAME
PDL::GSLSF::LEGENDRE - PDL interface to GSL Special Functions DESCRIPTION
This is an interface to the Special Function package present in the GNU Scientific Library. SYNOPSIS
Functions FUNCTIONS
gsl_sf_legendre_Pl Signature: (double x(); double [o]y(); double [o]e(); int l) P_l(x) gsl_sf_legendre_Pl does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_legendre_Pl_array Signature: (double x(); double [o]y(num); int l=>num) P_l(x) from 0 to n-1. gsl_sf_legendre_Pl_array does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_legendre_Ql Signature: (double x(); double [o]y(); double [o]e(); int l) Q_l(x) gsl_sf_legendre_Ql does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_legendre_Plm Signature: (double x(); double [o]y(); double [o]e(); int l; int m) P_lm(x) gsl_sf_legendre_Plm does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_legendre_Plm_array Signature: (double x(); double [o]y(num); int l=>num; int m) P_lm(x) for l from 0 to n-2+m. gsl_sf_legendre_Plm_array does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_legendre_sphPlm Signature: (double x(); double [o]y(); double [o]e(); int l; int m) P_lm(x), normalized properly for use in spherical harmonics gsl_sf_legendre_sphPlm does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_legendre_sphPlm_array Signature: (double x(); double [o]y(num); int n=>num; int m) P_lm(x), normalized properly for use in spherical harmonics for l from 0 to n-2+m. gsl_sf_legendre_sphPlm_array does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_conicalP_half Signature: (double x(); double [o]y(); double [o]e(); double lambda) Irregular Spherical Conical Function P^{1/2}_{-1/2 + I lambda}(x) gsl_sf_conicalP_half does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_conicalP_mhalf Signature: (double x(); double [o]y(); double [o]e(); double lambda) Regular Spherical Conical Function P^{-1/2}_{-1/2 + I lambda}(x) gsl_sf_conicalP_mhalf does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_conicalP_0 Signature: (double x(); double [o]y(); double [o]e(); double lambda) Conical Function P^{0}_{-1/2 + I lambda}(x) gsl_sf_conicalP_0 does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_conicalP_1 Signature: (double x(); double [o]y(); double [o]e(); double lambda) Conical Function P^{1}_{-1/2 + I lambda}(x) gsl_sf_conicalP_1 does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_conicalP_sph_reg Signature: (double x(); double [o]y(); double [o]e(); int l; double lambda) Regular Spherical Conical Function P^{-1/2-l}_{-1/2 + I lambda}(x) gsl_sf_conicalP_sph_reg does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_conicalP_cyl_reg_e Signature: (double x(); double [o]y(); double [o]e(); int m; double lambda) Regular Cylindrical Conical Function P^{-m}_{-1/2 + I lambda}(x) gsl_sf_conicalP_cyl_reg_e does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_legendre_H3d Signature: (double [o]y(); double [o]e(); int l; double lambda; double eta) lth radial eigenfunction of the Laplacian on the 3-dimensional hyperbolic space. gsl_sf_legendre_H3d does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. gsl_sf_legendre_H3d_array Signature: (double [o]y(num); int l=>num; double lambda; double eta) Array of H3d(ell), for l from 0 to n-1. gsl_sf_legendre_H3d_array does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. AUTHOR
This file copyright (C) 1999 Christian Pellegrin <chri@infis.univ.trieste.it> All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file. The GSL SF modules were written by G. Jungman. perl v5.12.1 2010-07-05 LEGENDRE(3)
All times are GMT -4. The time now is 03:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy