copying columns with headers' specific pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copying columns with headers' specific pattern
# 1  
Old 06-01-2010
Question extracting columns with headers' specific pattern

Hi friends,
I have data in tab separated file with headers like this :

*sml1 *sml3 *smln7 smfk9 smllf56...

Which shell command I should use if i want to extract entire columns that have header names beginning with "*" ? i want to copy these columns into another file.

Thanks,

Last edited by jacks; 06-01-2010 at 07:31 AM..
# 2  
Old 06-01-2010
Try:
Code:
grep '^\*' file > newfile

# 3  
Old 06-01-2010
Thanks. It did not work.
# 4  
Old 06-01-2010
How about:
Code:
awk '{for (i=1;i<=NF;i++) {if (NR==1 && $i~/^*/) A[i]; if (i in A) printf $i"\t"} print ""}' infile

# 5  
Old 06-01-2010
it keeps selecting all columns.
# 6  
Old 06-01-2010
Quote:
Originally Posted by jacks
Thanks. It did not work.
Sorry, I misread the question, try:
Code:
tr ' ' '\n' < file | grep '^\*' > newfile

# 7  
Old 06-01-2010
No, it still does not work.
Here is the sample data. It is in tab separated format. I want to select columns having header names starting with "*".
 
*smt_0018 smf_0031 *smlf_0042 *sugk_0053
11.2902 12.4807 10.7395 7.9672
8.98292 9.03125 9.69812 7.7105
7.71334 8.28308 8.05211 7.57295
9.07925 9.17628 8.96038 8.1141
10.1289 8.9778 9.17119 7.52616
11.5821 9.54838 8.76748 8.19344
9.18122 9.71467 10.1511 13.4099
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying specific file types to specific folders

I am trying to write a script that cycles through a folder containing many folders and when inside each one it's supposed to copy all the .fna.gz files to a folder elsewhere if the file and the respective folder have the same name. for fldr in /home/playground/genomes/* ; do find .... (8 Replies)
Discussion started by: Mr_Keystrokes
8 Replies

2. Shell Programming and Scripting

Copying files with a specific pattern

Hi All I am trying to copy files from one location to another and given below are some sample ones: aaa_bbb_ccc_ddd_cost_code_20140330.gz aaa_bbb_ccc_ddd_revenue_zone_20140329.gz aaa_bbb_ccc_ddd_benefit_extract_20140330.csv.gz aaa_bbb_ccc_ddd_profit_zone_20150509.csv.gz... (17 Replies)
Discussion started by: swasid
17 Replies

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

4. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

5. Shell Programming and Scripting

Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes. Is there a search for that? I tried cut but couldn't get it to work. Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print... (12 Replies)
Discussion started by: Drenhead
12 Replies

6. Shell Programming and Scripting

Transpose multipe columns to rows and adding headers

Hi, I found the following awk script to transpose multiple (3) columns to multiple rows: #=== BEGIN {FS=","} { for (i=1;i<=NF;i++) { arr=$i; if(nf<= NF) nf=NF; } nr=NR } END { for(i=1;i<=nf;i++) { (8 Replies)
Discussion started by: Gery
8 Replies

7. Shell Programming and Scripting

Merging of files with different headers to make combined headers file

Hi , I have a typical situation. I have 4 files and with different headers (number of headers is varible ). I need to make such a merged file which will have headers combined from all files (comman coluns should appear once only). For example - File 1 H1|H2|H3|H4 11|12|13|14 21|22|23|23... (1 Reply)
Discussion started by: marut_ashu
1 Replies

8. Shell Programming and Scripting

merge columns into one line after a specific pattern

Hi all, im a linux newbie, plz help! I have a file - box -------- Fox-2 -------- UF29 zip42 -------- zf-CW SNF2_N Heli_Z -------- Fox -------- Kel_1 box (3 Replies)
Discussion started by: sam_2921
3 Replies

9. UNIX for Dummies Questions & Answers

copying a pattern of files in one directory into other with new pattern names...

Hi, I have to copy a set of files abc* in /path/ to /path1/ as abc*_bkp. The list of files appear as follows in /path/: abc1 xyszd abc2 re2345 abcx .. . abcxyz I have to copy them (abc* files only) into /path1/ as: abc1_bkp abc2_bkp abcx_bkp .. . (6 Replies)
Discussion started by: new_learner
6 Replies

10. Shell Programming and Scripting

Copying specific files from remote m/c to specific folders

Hi All, I am trying to rsync some of the latest files from remote m/c to my local linux box. Folder structure in my remote m/c looks like this /pub/Nightly/Package/ROLL/WIN /pub/Nightly/Package/SOLL/sol /pub/Nightly/Package/SOLL/linux Each of the folder contains gzip files which on daily... (0 Replies)
Discussion started by: jhoomsharabi
0 Replies
Login or Register to Ask a Question