12-07-2011
Need to find a column from one file and print certain columns in second file
Hi,
I need helping in finding some of the text in one file and some columns which have same column in file 1
EG
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,afrewr32r,name,324324,age,sex.............
As you can see that the file is comma "," separated and name, age,sex may not be on same colunm.
my O/P should be in the following format
aaaa,name,age,sex
bbbb,s,name,age,sex
cccc,,name,age,sex
dddd,name,age,sex
I am trying the this command nawk -F="," 'NR==FNR{a[$1]=$0;next}{print $1 $3 $11,$1 in a?a[$1];"NOT FOUND"}' file_2 file_1.
For some reason it is failing. I am running this command on a solaris machine.
Any help is greatly appreciated. Thanks in advance.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
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
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
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
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
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
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
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
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
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
LEARN ABOUT ULTRIX
swap_sym
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)