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 DEBIAN
bones-info
BONES-INFO(1) User Contributed Perl Documentation BONES-INFO(1)
NAME
bones-info - display information about a Nethack bones file
SYNOPSIS
bones-info [-a | --auto] [-b | --big-endian] [--debug] [--help] [-x | --hexadecimal] [-l | --little-endian] [-v | --verbose] [--version]
file...
DESCRIPTION
bones-info displays information about a Nethack bones file. By default it shows what byte sex it used to read the file and the 4 version
numbers which constitute the feature set and platform for the Nethack binary which generated it.
ENDIANNESS (aka BYTE SEX)
Normally bones-info reads the bones file in little endian order, regardless of the byte sex of the current system, mostly because it was
originally written to help with diagnosing problems with hearse and that's the most useful behavior for that purpose. You can use the
--auto, --big-endian, and --little-endian switches to change this.
--auto is particularly useful (and appropriate) when using --verbose.
OPTIONS
-a, --auto
Try to guess the right byte sex (little endian or big endian) for each input file. If there doesn't seem to be a right choice, bones-
info will output a warning, set a non-zero exit status, and move on to the next file.
-b, --big-endian
Read the bones files in big endian order, such as is used by Macs. See also "--auto".
--debug
Turn debugging on.
--help
Show the usage message and die.
-x, --hexadecimal
Output numbers in hexadecimal form.
-l, --little-endian
Read the bones files in little endian order, such as is used by Intel hardware. This is the default, I include it so that you don't
have to check what the default is if you know you want it a certain way.
-v, --verbose
Output more info about the bones file. This tries to decode the 4 version numbers. Its useful when you want to see what the
differences are between two sets of version numbers. You'd normally want to use --auto when you use --verbose.
--version
Show the version number and exit.
EXAMPLES
Output the values as used by the hearse server:
$ bones-info *
bonD0.0 sex=l v1=1 v2=2 v3=3 v4=4
bonD0.4.gz sex=l v1=50593792 v2=10357958 v3=555422078 v4=2759955912
bonD0.8.Z sex=l v1=1027 v2=3322682880 v3=2115050273 v4=3365241252
bonD0.19 sex=l v1=50528512 v2=10357830 v3=555409789 v4=2558629316
bonM0.1 sex=l v1=50593792 v2=404622406 v3=555417981 v4=2759955916
bonM0.T sex=l v1=50593792 v2=1969222 v3=555417981 v4=2759955912
Output the real values as seen on the system which wrote the file (by guessing the byte sex of the file):
$ bones-info --auto *
bones-info: can't intuit byte sex of bonD0.0
bonD0.4.gz sex=l v1=50593792 v2=10357958 v3=555422078 v4=2759955912
bonD0.8.Z sex=b v1=50593792 v2=1969350 v3=555422078 v4=2759955912
bonD0.19 sex=l v1=50528512 v2=10357830 v3=555409789 v4=2558629316
bonM0.1 sex=l v1=50593792 v2=404622406 v3=555417981 v4=2759955916
bonM0.T sex=l v1=50593792 v2=1969222 v3=555417981 v4=2759955912
zsh: exit 1 bones-info --auto *
Decode the version numbers:
$ bones-info --auto --verbose bonD0.4.gz bonD0.8.Z
bonD0.4.gz: 18389 bytes
read as: little endian
incarnation: 50593792 (3.4.0.0)
feature_set: 10357958 (REINCARNATION SINKS KOPS MAIL TOURIST STEED
TEXTCOLOR INSURANCE ELBERETH EXP_ON_BOTL
TIMED_DELAY)
entity_count: 555422078 (33 artifacts, 433 objects, 382 monsters)
struct_sizes: 2759955912 (164 flag, 64 obj, 101 monst, 456 you)
bonD0.8.Z: 22296 bytes
read as: big endian
incarnation: 50593792 (3.4.0.0)
feature_set: 1969350 (REINCARNATION SINKS KOPS MAIL TOURIST STEED
TEXTCOLOR INSURANCE ELBERETH EXP_ON_BOTL)
entity_count: 555422078 (33 artifacts, 433 objects, 382 monsters)
struct_sizes: 2759955912 (164 flag, 64 obj, 101 monst, 456 you)
$ _
BUGS
Unsigned longs are assumed to be 4 bytes.
The --auto byte sex detection isn't robust.
It'd be nice to be provide --verbose output for bones files from older versions.
AVAILABILITY
This program is distributed with the Unix Hearse client. The code is licensed under the GNU GPL. Check
http://www.argon.org/~roderick/hearse/ for updated versions.
AUTHOR
Roderick Schertler <roderick@argon.org>
perl v5.14.2 2012-02-11 BONES-INFO(1)