Sponsored Content
Top Forums Shell Programming and Scripting Need to find a column from one file and print certain columns in second file Post 302579864 by jpkumar10 on Wednesday 7th of December 2011 12:15:46 AM
Old 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

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
gd_alter_endianness(3)						      GETDATA						    gd_alter_endianness(3)

NAME
gd_alter_endianness -- modify the byte sex of fields in a dirfile SYNOPSIS
#include <getdata.h> int gd_alter_endianness(DIRFILE *dirfile, unsigned long byte_sex, int fragment_index, int recode); DESCRIPTION
The gd_alter_endianness() function sets the byte sex of the format specification fragment given by fragment_index to byte_sex in the dirfile(5) database specified by dirfile. The byte sex of a fragment indicate the endianness of data stored in binary files associated with RAW fields defined in the specified fragment. The byte sex of a fragment containing no RAW fields is ignored. The byte_sex argument should be one of the following: 0 (zero) Indicating that the byte sex should be the native endianness of the host, whichever that may be. GD_BIG_ENDIAN Indicating that the byte sex should be big endian. GD_LITTLE_ENDIAN Indicating that the byte sex should be little endian. (GD_BIG_ENDIAN | GD_LITTLE_ENDIAN) Indicating that the byte sex should be the opposite of the native endianness of the host, whichever that may be. Furthermore, any of these may be bitwise or'd with GD_ARM_ENDIAN or GD_NOT_ARM_ENDIAN indicating that the floating point data are stored in the ARM middle-endian format. In addition to being simply a valid fragment index, fragment_index may also be the special value GD_ALL_FRAGMENTS, which indicates that the byte sex of all fragments in the database should be changed. If the recode argument is non-zero, this call will byte swap the binary data of affected RAW fields to account for the change in byte sex. If the encoding of the fragment is endianness insensitive, or if the data type is only one byte in size, no change is made. If recode is zero, affected binary files are left untouched. RETURN VALUE
Upon successful completion, gd_alter_endianness() returns zero. On error, it returns -1 and sets the dirfile error to a non-zero error value. Possible error values are: GD_E_ACCMODE The specified dirfile was opened read-only. GD_E_ALLOC The library was unable to allocate memory. GD_E_BAD_DIRFILE The supplied dirfile was invalid. GD_E_BAD_INDEX The supplied index was out of range. GD_E_PROTECTED The metadata of the indicated format specification fragment was protected from change, or the binary data of the fragment was pro- tected from change and binary file byte swapping was requested. GD_E_RAW_IO An I/O error occurred while attempting to byte swap a binary file. GD_E_UNCLEAN_DB An error occurred while moving the byte-swapped file into place. As a result, the database may be in an unclean state. See the NOTES section below for recovery instructions. In this case, the dirfile will be flagged as invalid, to prevent further database corruption. It should be immediately closed. GD_E_UNKNOWN_ENCODING The encoding scheme of the fragment is unknown. GD_E_UNSUPPORTED The encoding scheme of the fragment does not support binary file byte swapping. The dirfile error may be retrieved by calling gd_error(3). A descriptive error string for the last error encountered can be obtained from a call to gd_error_string(3). NOTES
A binary file byte swap occurs out-of-place. As a result, sufficient space must be present on the filesystem for the binary files of all RAW fields in the fragment both before and after translation. If all fragments are updated by specifying GD_ALL_FRAGMENTS, the byte swap- ping occurs one fragment at a time. An error code of GD_E_UNCLEAN_DB indicates a system error occurred while moving the byte-swapped binary data into place or when deleting the old data. If this happens, the database may be left in an unclean state. The caller should check the filesystem directly to ascertain the state of the dirfile data before continuing. For recovery instructions, see the file /usr/share/doc/getdata/unclean_database_recov- ery.txt. SEE ALSO
gd_open(3), gd_error(3), gd_error_string(3), gd_endianness(3), dirfile(5), dirfile-format(5) Version 0.7.0 21 October 2010 gd_alter_endianness(3)
All times are GMT -4. The time now is 11:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy