12-14-2005
Match & append the files
Hi All,
I have a problem in appending the files
File 1
0.0000001 0.500000039894
0.0000002 0.500000079788
0.0000003 0.500000119683
0.0000004 0.500000159577
0.0000005 0.500000199471
0.0000006 0.500000239365
0.0000007 0.500000279260
0.0000008 0.500000319154
0.0000009 0.500000359048
0.0000010 0.500000398942
File 2
0.0000001 -5.199337582193
0.0000002 -5.068957749718
0.0000003 -4.991217139908
0.0000004 -4.935367444719
0.0000005 -4.891638475699
The output should be something like
0.0000001 0.500000039894 -5.199337582193
0.0000002 0.500000079788 -5.068957749718
0.0000003 0.500000119683 -4.991217139908
0.0000004 0.500000159577 -4.935367444719
0.0000005 0.500000199471 -4.891638475699
0.0000006 0.500000239365
0.0000007 0.500000279260
0.0000008 0.500000319154
0.0000009 0.500000359048
0.0000010 0.500000398942
I searched the forum and was able to figure that it can be done using the following awk command.
nawk -f app.awk File2 File1
Code for app.awk:
BEGIN { FS=OFS=" " }
FNR == NR { arr[$1]=$2; next }
{ $NF=($1 in arr) ? arr[$1] : " "; print }
But still the output is not as expected. I am getting the output as
0.0000001 -5.199337582193
0.0000002 -5.068957749718
0.0000003 -4.991217139908
0.0000004 -4.935367444719
0.0000005 -4.891638475699
0.0000006
0.0000007
0.0000008
0.0000009
0.0000010
Please help me...
Thanks
Shash
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have some question and need some guidance how to sort and match multiple files.
1. all the data in the files are numbers
e.g. 1234567
1584752
2563156
2. each sorted file have their own ouput. e.g. test.csv -> test_sorted.csv
3. Then, I need to match all... (4 Replies)
Discussion started by: nazri76
4 Replies
2. Shell Programming and Scripting
Using a bash script, I need to find all files in a folder "except" the newest file. Then I need to insert the contents of one text file into all the files found. This text needs to be placed at the beginning of each file and needs a blank line between it and the current contents of the file. Then I... (5 Replies)
Discussion started by: Trapper
5 Replies
3. UNIX for Dummies Questions & Answers
Hi,
I need help on appending certain field in my file1.txt based on matched patterns in file2.txt using awk or sed.
The blue color need to match with one of the data in field $2 in file2.txt. If match, BEGIN and FINISHED value in red will have a new value from field $3 and $4 accordingly.
... (1 Reply)
Discussion started by: redse171
1 Replies
4. Shell Programming and Scripting
I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from
both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6.
Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies
5. Shell Programming and Scripting
Hi,
I need help with this-
input.txt :
L B white
X Y white
A B brown
M Y black
Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt.
If 3rd column is brown, add different set of lines to insert.txt, and so on.
For example, the given... (6 Replies)
Discussion started by: prashob123
6 Replies
6. Shell Programming and Scripting
file
11 2
12 6
13 7
114 6
011 7
if I'm searching for 11, output needed is
output:
11 2
011 7
Code: awk '$1 ~ /^11$/' file
I used the above to match exact, but it avoiding "011 7" line too, how to resolve this? (6 Replies)
Discussion started by: Roozo
6 Replies
7. Shell Programming and Scripting
Not Sure how to do this. Some combo of awk and sed perhaps. If String in File1 match String in file2 then append file2
File1.txt
BullTerrier
Boxer
Bulldog
File2.txt
<Defined info="AllAnimals" group="Adoptions" setting="animals">
<SomeID ="NumbersRepresentingDogName">
<for>
<add... (2 Replies)
Discussion started by: TY718
2 Replies
8. Shell Programming and Scripting
ALL,
Please help with this ...
File1
000433,ds00d11,tdev,ds00d11_view,0CD3
000433,ds00d12_34,tdev,ds00d12_view,132D
File2
CG01_ds00d11_drs,rs1_ds00d11_0CD3_114D,000433,0CD3
CG01_ds00d11_drs,rs1_ds00d11_0CD3_114D,000566,114D
... (6 Replies)
Discussion started by: greycells
6 Replies
9. Shell Programming and Scripting
Hello,
I have a file contains two columns. I need to print the lines after “xxx” so i'm trying to match "xxx" & cut the lines after that. I'm trying with the grep & cut command, if there any simple way to extract this please help me.
Sample file :
name id
AAA 123
AAB 124
AAC 125... (4 Replies)
Discussion started by: Shenbaga.d
4 Replies
10. Shell Programming and Scripting
I am trying to parse two csv files and make a match in one column then print the entire file to a new file and append an additional column that gives description from the match to the new file. If a match is not made, I would like to add "NA" to the end of the file
Command that Ive been using... (6 Replies)
Discussion started by: dis0wned
6 Replies
LEARN ABOUT ULTRIX
filehdr
filehdr(5) File Formats Manual filehdr(5)
Name
filehdr - file header for RISC object files
Syntax
#include < filehdr.h>
Description
Every RISC object file begins with a 20-byte header. The following C struct declaration is used:
struct filehdr
{
unsigned short f_magic; /* magic number */
unsigned short f_nscns; /* number of sections */
long f_timdat; /* time & date stamp */
long f_symptr; /* file pointer to symbolic header */
long f_nsyms; /* sizeof(symbolic header) */
unsigned short f_opthdr; /* sizeof(optional header) */
unsigned short f_flags; /* flags */
};
The byte offset into the file at which the symbolic header can be found is f_symptr. Its value can be used as the offset in to position an
I/O stream to the symbolic header. The ULTRIX system optional header is 56 bytes. The valid magic numbers are given below:
#define MIPSEBMAGIC 0x0160 /* objects for big-endian machines */
#define MIPSELMAGIC 0x0162 /* objects for little-endian machines */
#define MIPSEBUMAGIC 0x0180 /* ucode objects for big-endian machines */
#define MIPSELUMAGIC 0x0182 /* ucode objects for little-endian machines */
RISC object files can be loaded and examined on machines differing from the object's target byte sex. Therefore, for object file magic
numbers, the byte-swapped values have define constants associated with them:
#define SMIPSEBMAGIC 0x6001
#define SMIPSELMAGIC 0x6201
The value in f_timdat is obtained from the system call. Flag bits used in RISC objects are:
#define F_RELFLG 0000001 /* relocation entries stripped */
#define F_EXEC 0000002 /* file is executable */
#define F_LNNO 0000004 /* line numbers stripped */
#define F_LSYMS 0000010 /* local symbols stripped */
See Also
time(2), fseek(3s), a.out(5)
RISC filehdr(5)