09-07-2002
This worked for me in a similar situation as you described...
It works in two parts...
First the join command to create the delimited file from the two separate files. (The -j1, and the ~/file1 correlate to one another, and the -j2 and the ~/file2 correlate to one another):
join -a1 -t"|" -j1 1 -j2 1 -o 1.1 -o 1.2 /directory/path/here/file1 /directory/path/here/file2 > joinedfile.name
This join compares the first field of each file and joins them together if a match if found...Kind of like a query in a database matching keys. The -o specifies which fields are kept and their order in the final output file. So 1.1 would mean keep field one in file one, and 2.1 would mean keep field one in file two...
You can join multiple files this way by simply adding another line of code and specifying that the output concantenate (>>) to the end of the file you're building.
join -a1 -t"|" -j1 1 -j2 1 -o 1.1 -o 2.1 1.2 /directory/path/here/file3 /directory/path/here/file2 >> joinedfile.name
then the awk command. The delimiter is set using the switch \|:
awk -F"|" '{printf "%s\|%s\|\n",$1,$2}' joinedfile.name > finalfile.name
Let me know if this makes sense or if it even serves your purpose.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all, i am writting a script to fix some problems we have with data that we need that contains 1000s of records. I have a text file with 3 columns of data. The problem is there should be a space between the end of the first column and the start of the second column. The majority of the data is... (7 Replies)
Discussion started by: borderblaster
7 Replies
2. Shell Programming and Scripting
Hello,
I am newbie in awk. I have just started learning it.
1) I have input file which looks like:
{4812 4009 1602 2756 306} {4814 4010 1603 2757 309} {8116 9362 10779 }
{10779 10121 9193 10963 10908} {1602 2756 306 957 1025} {1603 2757 307}
and so on.....
2) In output:
a)... (10 Replies)
Discussion started by: kajolo
10 Replies
3. Shell Programming and Scripting
Actually I got a list of file end with *.txt
I want to use the same command apply to all the *.txt
Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics.
For example:
I got the file below:
file1.txt
file2.txt
file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies
4. Shell Programming and Scripting
Hi Experts,
I am adding a column of numbers with awk , however not getting correct output:
# awk '{sum+=$1} END {print sum}' datafile
2.15291e+06
How can I getthe output like : 2152910
Thank you..
# awk '{sum+=$1} END {print sum}' datafile
2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies
5. Shell Programming and Scripting
Hi
I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it
The code is that:
{
if (NF==17){
print $0
}else{
fields=NF;
all=$0;
while... (2 Replies)
Discussion started by: fate
2 Replies
6. Shell Programming and Scripting
Hi,
I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files.
To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies
7. Shell Programming and Scripting
Hello experts,
I'm stuck with this script for three days now. Here's what i need.
I need to split a large delimited (,) file into 2 files based on the value present in the last field.
Samp: Something.csv
bca,adc,asdf,123,12C
bca,adc,asdf,123,13C
def,adc,asdf,123,12A
I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies
8. Shell Programming and Scripting
Hi,
I have an output after performing a grep:
FAN
and i did awk '{print $2}' it shows:
is there a way, by using sed that it will only show output as NO_FAULT without the brackets ?
i tried doing sed 's/^*//' but the output is
NO_FAULT] with the ] at the... (12 Replies)
Discussion started by: mosies
12 Replies
9. Shell Programming and Scripting
consider the script below
sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml
awk -F'' '{for(i=1;i<=NF;i++){
if($i=="Alert id") {
if(id!="")
if(dt!=""){
cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies
10. Shell Programming and Scripting
Good evening, Im newbie at unix specially with awk
From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example
1.
This is the inputfile:
$ more MapaRep.txt
ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies