Sponsored Content
Top Forums Shell Programming and Scripting merging two files with one word Post 302269412 by tadasvu on Wednesday 17th of December 2008 03:01:11 PM
Old 12-17-2008
Quote:
Originally Posted by vgersh99
nawk -f tada.awk file1 file2

tada.awk:
Code:
FNR==NR { 
          for(i=2; i<=NF; i++) f1[$1] = ($1 in f1) ? f1[$1] OFS $i : $i
          next
}

$1 in f1 {
   if (!($1 in f2))
      f2[$1]=f1[$1]
   for(i=2; i<=NF; i++) f2[$1] = f2[$1] OFS $i
}
END {
  for (i in f2)
    print i, f2[i]
}

thanks it works just fine with that example, but then files a bigger it get's messy. Now i realize whats wrong, if there is same 00:00:23:03:04 several times. let's say the
first file is:
Code:
omg omg omg
omg omg omg
00:00:23:03:04 stanga laba7123 
00:03:24:03:04 jonas laba324 
omg omg omg
00:00:23:03:04 stanga laba7123
omg omg omg

second is:
Code:
00:00:23:03:04 whatever goes here
00:03:24:03:04 and here
00:00:23:03:04 and even here

output:

00:00:23:03:04 stanga laba7123 whatever goes here
00:03:24:03:04 jonas laba324 and here
00:00:23:03:04 stanga laba7123 and even here

it could realize that the same first word could be later in the first file.

now i get:

Code:
00:00:23:03:04 stanga laba7123 stanga laba7123 whatever goes here and even here
00:03:24:03:04 jonas laba324 and here


Last edited by tadasvu; 12-17-2008 at 04:19 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Merging files

Hi i have two files say file 1 contents are A B C D E I have file2 contents are B E F G C K I want to have new file like A B (4 Replies)
Discussion started by: ssuresh1999
4 Replies

2. Shell Programming and Scripting

merging two files

Friends, os: redhat enterprise linux/SCO UNIX5.0 I have two files and I would like to merge on given key value. Now I have tried with join commd but it does not supporte multiple delimiters. and if records length is not fixed. join -a1 5 -a2 1 -t -o file1 file2 > outname Can any... (7 Replies)
Discussion started by: vakharia Mahesh
7 Replies

3. Shell Programming and Scripting

merging two files

Hi everyone, I have two files which will be exactly same at first. After sometime there will be inserts in one file. My problem is how to reflect these changes in second file also. I found out that any compare and merge utility would do the job like, GNU " sdiff " command. But the... (14 Replies)
Discussion started by: rameshonline
14 Replies

4. Shell Programming and Scripting

merging of files.

Hi, I want to merge the two files on the basis of columns like... file 1 Data Key A 12 B 13 file2 Data Value A A1 A A2 B B1 B B2 (5 Replies)
Discussion started by: clx
5 Replies

5. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

6. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

7. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

8. Shell Programming and Scripting

Merging two files

Guys, I am having little problem with getting a daily report! The daily process that I do is as follows 1. Unload Header for the report from the systables to one unl file, say Header.unl 2. Unload the data from the required table/tables to another unl file, say Data.unl 3. Send a... (2 Replies)
Discussion started by: PikK45
2 Replies

9. Shell Programming and Scripting

Merging two files

Hi All , I have a scenario where we need to combine two files . Below are the sample files and expected output , File 1: 1|ab 1|ac 1|ae 2|ad 2|ac File 2: 1|xy 1|fc 2|gh 2|ku Output file : 1|ab|xy (3 Replies)
Discussion started by: saj
3 Replies

10. Shell Programming and Scripting

Find a word and increment the number in the word & save into new files

Hi All, I am looking for a perl/awk/sed command to auto-increment the numbers line in file, P1.tcl: run_build_model sparc_ifu_dec run_drc set_faults -model path_delay -atpg_effectiveness -fault_coverage add_delay_paths P1 set_atpg -abort_limit 1000 run_atpg -ndetects 1000 I would like... (6 Replies)
Discussion started by: jypark22
6 Replies
JAPIZE(1)						      General Commands Manual							 JAPIZE(1)

NAME
japize - Produce a listing of an API in a machine-readable format. SYNOPSIS
japize [unzip] [as <name>] apis <zipfile>|<dir> ... +|-<pkgpath> ... DESCRIPTION
japize is part of japitools, designed to test for compatibility between Java APIs. They were originally designed for testing free implementations of Java itself for compatibility with Sun's JDK, but they can also be used for testing backward compatibility between versions of any API. The tools are japize and japicompat. Japize is a Java program which emits a listing of an API in a machine-readable format. Japicompat then takes two such listings and compares them for binary compatibility, as defined by Sun in the Java Language Specification. At least one +<pkgpath> is required. <name> will have ".japi" and/or ".gz" appended as appropriate. The word "apis" can be replaced by "explicitly", "byname", "packages" or "classes". These options indicate whether something of the form "a.b.C" should be treated as a class or a package. You may specify this unambiguously by using one of the forms "a.b.cpackage," or "a.b,CClass". OPTIONS
unzip disable zipping of the output with gzip. Zipping the output is highly recommended since it saves huge amounts of space. The only situations where you might not want to use gzip compression are when memory and CPU usage are extremely tight or if your JVM does not implement GZIPOutputStream correctly (in which case you might still want to gzip the resulting file manually). as <name> Specifying this option tells japize to write its output to a file with the specified name. When writing to a file with the "as" option, japize insists on writing to a file name ending in .japi.gz for compressed files, or .japi for uncompressed files. If the filename you specify doesn't have the right extension, japize will add parts to it to ensure that it does. If the "as" option is omitted, japize will write to standard output. In this case japize has no control over the filename you use, but it is strongly recommended to use a filename with the correct extension (".japi.gz" unless the "unzip" option was specified). If you use any other extension, japicompat and other tools may be unable to recognize the format. apis | explicitly | byname | packages | classes This option has a dual role: it indicates the boundary between japize options (unzip, as) and other arguments (files and packages), but also tells japize how to deal with ambiguously specified arguments. See "+|-<pkgpath>" below for details on the behavior of each option. If you are unsure which to specify, "apis" is a safe choice. apis a.b.c is tried both as a package and a class. This will always do what you want (which is why apis is described as the safe default) but at the expense of possibly doing extra unnecessary processing trying to find the wrong thing. explicitly pkgpaths of the form a.b.c are illegal - you must use the explicit form. byname a.b.c will be processed as a package if "c" starts with a lowercase letter, or as a class if it starts with an uppercase one. This usually does what you want but fails on things like org.omg.CORBA. packages a.b.c will be processed as a package. If processing for a class is needed, it must be specified explicitly. classes a.b.c will be processed as a class. If processing for a package is needed, it must be specified explicitly. <zipfile> | <dir> Any arguments after "apis" that do not start with "+" or "-" are taken to be zipfiles or directories. These should be specified exactly as you would put them in your CLASSPATH (except separated by spaces rather than colons). Anything that's a file will be assumed to be a zip (or jar) file, so you can't specify a .class file directly - if you need to do that you should specify the folder containing it and then name the class for processing. +|-<pkgpath> To specify which classes are included, use +pkgpath to add pkgpaths to be scanned and -pkgpath to exclude sub-pkgpaths of these. You MUST specify at least one +pkgpath option to specify which pkgpath to include, otherwise Japize could happily scan through all the zipfiles and directories but not actually process any of the classes. Since that would be a useless thing to do, japize gives an error instead. A "pkgpath" refers to either a package (which includes, by implication, all sub-packages of it) or a single class. A pkgpath for a package looks like "com.foo.pkg.sub," and a pkgpath for a class looks like "com.foo.pkg,Cls". The existence and placement of the comma indicates unambiguously which type of path is intended. Most of the time, though, it's a pain to have to put in commas in names that are familiar with dots instead, and get the comma placement exactly right. For this reason, japize accepts pkgpaths containing only dots, and lets you tell it what to make of those names. The interpretation of "a.b.c" as a pkgpath depends on whether you specified apis, explicitly, byname, packages, or classes. EXAMPLE
Sun's JDK 1.1 includes classes in java.awt.peer and in java.text.resources that are not part of the public API, even though they are public classes; however, every other class in the java.* package hierarchy is part of the public API. The syntax to construct a useful jdk11.japi.gz would therefore be: $ japize as jdk11 apis classes.zip +java -java.awt.peer -java.text.resources Note that since all pkgpath arguments here are packages, you could save a small amount of processing by doing this instead: $ japize as jdk11 packages classes.zip +java -java.awt.peer -java.text.resources or even this: $ japize as jdk11 explicitly classes.zip +java, -java.awt.peer, -java.text.resources, SEE ALSO
japicompat(1) Test Java APIs for binary backwards compatibility. japilist(1) List the contents of japi files. japiohtml(1) Convert japicompat output to pretty html format. japiotext(1) Convert japicompat output to readable plain text format. October 6, 2005 JAPIZE(1)
All times are GMT -4. The time now is 03:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy