Sponsored Content
Top Forums Shell Programming and Scripting Need to find a column from one file and print certain columns in second file Post 302579870 by durden_tyler on Wednesday 7th of December 2011 01:30:25 AM
Old 12-07-2011
Code:
$
$
$ cat file_1
aaaa
bbbb
cccc
dddd
eeee
fffff
gggg
hhhh
$
$
$ cat file_2
aaaa,abcd,effgh,ereref,name,age,sex
bbbb,efdfh,erere,afdafds,name,age,sex
cccc,q134321,34324,afadf_2343,name,age,sex
dddd,143243,234324,afde3q4r,name,age,sex
$
$
$ perl -F, -lane 'if ($ARGV eq "file_1") {$x{$_}++} elsif (defined $x{$F[0]}){print join ",", @F[0,4..6]}' file_1 file_2
aaaa,name,age,sex
bbbb,name,age,sex
cccc,name,age,sex
dddd,name,age,sex
$
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check Null values in a file column by column if columns are Not NULLs

Hi All, I have a table with 10 columns. Some columns(2nd,4th,5th,7th,8th and 10th) are Not Null columns. I'll get a tab-delimited file and want to check col by col and generate seperate error code for each col eg:102 if 2nd col value is NULL and 104 if 4th col value is NULL so on... I am a... (7 Replies)
Discussion started by: Mandab
7 Replies

2. UNIX for Dummies Questions & Answers

find locked files, print file path, unlock file

using OS X and the Terminal, I'd like to find all locked files in a specified directory, unlock them, and print a list of those files that were unlocked how can I do this? I'm familiar with chflags nouchg for unlocking one file but not familiar with unix enough to do what I'd like. Thanks! (0 Replies)
Discussion started by: alternapop
0 Replies

3. Shell Programming and Scripting

Print columns in a file by number list in another file

This should follow with my last post but I think it's better to start a new one. Now I have a list of numbers stored in pos.txt: 2 6 7 . . . n . . . And I need to extract (2n-1, 2n) columns from matrix.txt: ind1 A B C D E F G H I J K L M N O P Q R ... ind2 B C D E F G H... (3 Replies)
Discussion started by: Zoho
3 Replies

4. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

5. UNIX for Dummies Questions & Answers

Print entire columns into new file

Dear All, I am having trouble obtaining the 3 outfiles (as shown below) from a single input file. Could you please help?? INPUT: filename a b c 1 4 2 3 3 2 4 2 7 OUTPUT: outfile1 (a.dat) 1 (2 Replies)
Discussion started by: chen.xiao.po
2 Replies

6. Shell Programming and Scripting

comparing column of two different files and print the column from in order of 2nd file

Hi friends, My file is like: Second file is : I need to print the rows present in file one, but in order present in second file....I used while read gh;do awk ' $1=="' $gh'" {print >> FILENAME"output"} ' cat listoffirstfile done < secondfile but the output I am... (14 Replies)
Discussion started by: CAch
14 Replies

7. Shell Programming and Scripting

Match and print columns in second file

Hi All, I have to match each row in file 1 with 1st row in file 2 and print the corresponding column from file2. I am trying to use an awk script to do this. For example cat File1 X1 X3 X4 cat File2 ID X1 X2 X3 X4 A 1 6 2 1 B 2 7 3 3 C 3 8 4 1 D 4 9 1 1 (3 Replies)
Discussion started by: newpro
3 Replies

8. Shell Programming and Scripting

Filtering first file columns based on second file column

Hi friends, I have one file like below. (.csv type) SNo,data1,data2 1,1,2 2,2,3 3,3,2 and another file like below. Exclude data1 where Exclude should be treated as column name in file2. I want the output shown below. SNo,data2 1,2 2,3 3,2 Where my data1 column got removed from... (2 Replies)
Discussion started by: ks_reddy
2 Replies

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

10. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies
swapsex(3)						     Library Functions Manual							swapsex(3)

Name
       swap_word,  swap_half, swap_filehdr, swap_aouthdr, swap_scnhdr, swap_hdr, swap_fd, swap_fi, swap_sym, swap_ext, swap_pd, swap_dn, swap_opt,
       swap_aux, swap_reloc, swap_ranlib - swap the sex of the specified structure

Syntax
       #include <sex.h>
       #include <filehdr.h>
       #include <aouthdr.h>
       #include <scnhdr.h>
       #include <sym.h>
       #include <symconst.h>
       #include <cmplrs/stsupport.h>
       #include <reloc.h>
       #include <ar.h>

       long swap_word( word )
       long word;

       short swap_half( half )
       short half;

       void swap_filehdr( pfilehdr, destsex )
       FILHDR *pfilehdr;
       long destsex;

       void swap_aouthdr( paouthdr, destsex )
       AOUTHDR *paouthdr;
       long destsex;

       void swap_scnhdr( pscnhdr, destsex )
       SCNHDR *pscnhdr;
       long destsex;

       void swap_hdr( phdr, destsex )
       pHDRR phdr;
       long destsex;

       void swap_fd( pfd, count, destsex )
       pFDR pfd;
       long count;
       long destsex;

       void swap_fi( pfi, count, destsex )
       pFIT pfi;
       long count;
       long destsex;

       void swap_sym( psym, count, destsex )
       pSYMR psym;
       long count;
       long destsex;

       void swap_ext( pext, count, destsex )
       pEXTR pext;
       long count;
       long destsex;

       void swap_pd( ppd, count, destsex )
       pPDR ppd;
       long count;
       long destsex;

       void swap_dn( pdn, count, destsex )
       pRNDXR pdn;
       long count;
       long destsex;

       void swap_opt( popt, count, destsex )
       pOPTR popt;
       long count;
       long destsex;

       void swap_aux( paux, type, destsex )
       pAUXU paux;
       long type;
       long destsex;

       void swap_reloc( preloc, count, destsex )
       struct reloc *preloc;
       long count;
       long destsex;

       void swap_ranlib( pranlib, count, destsex )
       struct ranlib *pranlib;
       long count;
       long destsex;

Description
       All routines that swap headers take a pointer to a header structure to change the byte's sex. The destsex argument lets	the  swapsex  rou-
       tines decide whether to swap bitfields before or after swapping the words in which they occur. If destsex equals the hostsex of the machine
       you are running on, the flip happens before the swap; otherwise, the flip happens after the swap.  Although not all  routines  swap  struc-
       tures containing bitfields, the destsex is required.

       The  routine  takes  a  pointer to an aux entry and a type, which is a ST_AUX_* constant in cmplrs/stsupport.h.	The constant specifies the
       type of the aux entry to change the sex of.  All other routines are passed a pointer to an array of structures and a count of structures to
       have  the  byte	sex  changed.	The  routines and are macros declared in sex.h.  Only the include files that describe the structures being
       swapped have to be included.

See Also
       gethostsex(3)

								       RISC								swapsex(3)
All times are GMT -4. The time now is 04:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy