Sponsored Content
Top Forums Shell Programming and Scripting Merging data from 2 files of different lengths? Post 302553176 by Ygor on Wednesday 7th of September 2011 02:17:24 AM
Old 09-07-2011
Try...
Code:
$ head vessel_file job_file
==> vessel_file <==
TIAN XING HE,018S,110904,1400
ANL WARRAIN,032S,110909,0635
HS WAGNER,1133S,110905,2000
LONG MU WAN,1113S,110908,1400
SANTA MONICA,004S,110819,0630
HANJIN PORT ADELAIDE,785,110901,0630
ATHENA,134S,110905,1000
CSCL SANTIAGO,0050S,110829,1100
JPO VELA,132S,110831,1430
DIAMANTIS P,783,110823,1430

==> job_file <==
1018003,LONG MU WAN,1113S
1018004,LONG MU WAN,1113S
1018024,HS WAGNER,1133S
1018026,ANL WARRAIN,032S
1018032,TIAN XING HE,018S
1018055,TIAN XING HE,018S
1018057,LONG MAN BILL,918S

$ awk 'BEGIN{FS=OFS=","}NR==FNR{a[$1]=$3 FS $4;next}a[$2]{print $0,a[$2]}' vessel_file job_file > output_file

$ cat output_file
1018003,LONG MU WAN,1113S,110908,1400
1018004,LONG MU WAN,1113S,110908,1400
1018024,HS WAGNER,1133S,110905,2000
1018026,ANL WARRAIN,032S,110909,0635
1018032,TIAN XING HE,018S,110904,1400
1018055,TIAN XING HE,018S,110904,1400

This User Gave Thanks to Ygor For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merging data

Hi, I have the following problem: Input: "num1","num2","num3",num4,num5,"num6" required output: "num1num2","num3",num4,num5,"num6" I need to join field 1 and field 2 together but I always end up getting: "num1""num2","num3",num4,num5,"num6" Note that not all fields have " at both... (8 Replies)
Discussion started by: ReV
8 Replies

2. Shell Programming and Scripting

Need help for 2 data file merging

Hello Please help me to write Shell script. I want to merge 2 data files . The data files have common columns The data file A have 3 columns Host Version Numberof Failuers The data file B have also 3 coulmns Host Version NumberofFailuers . I want to merge A and B file... (2 Replies)
Discussion started by: getdpg
2 Replies

3. Shell Programming and Scripting

Merging last and syslog data on time

This is on a HP-UX system. I need to merge the 2 reports, for each line in syslog I need to lookup who was logged in to the pts/# based on the time from the last.txt report. Here is what I get from sulog.log cat syslog | grep "su:" | grep "Jun 14" Jul 14 08:02:48 server1 su: - 2 ... (8 Replies)
Discussion started by: Ikon
8 Replies

4. Shell Programming and Scripting

formatting and merging 2 data files

Hi, I have 2 files that I got as an output from another program. They are : File 1 ((((((CtBJa:197.0,CtBTz:197.0):85.0,CtAHr:197.0):116.0,CtDUw:197.0):176.0,CtSwe:197.0):110.0, (CtL2b:197.0,Ct4Bu:197.0):196.0):197.0,CmuNg:197.0);... (5 Replies)
Discussion started by: Lucky Ali
5 Replies

5. Shell Programming and Scripting

Merging data from one file into another

Hello, I have a master database of a dictionary with the following structure: a=b (b is a Unicode string) a is the English part and b is the equivalent in a foreign language I have also another file which has a database where the /b/ part of the string has been corrected by an expert. let us... (5 Replies)
Discussion started by: gimley
5 Replies

6. UNIX for Dummies Questions & Answers

Merging data in a file

Hello, Firstly I just wanted to say that I'm not a programmer at all and appreciate any help you can give. I am trying to create a shellscript that reformats the file and adding up colums 5 and 6 for those sections that are continuation of the previous line(s) (signified by beginning with '*')... (4 Replies)
Discussion started by: neilh1703
4 Replies

7. Shell Programming and Scripting

Help with merging data into single line.

Hi, My input is <message> looking for a big <message>Does fit my G74 laptop. Makes the 10 pound. <message> <message>This bag is the only one I could find to fit my awesome ASUS G74S. <message> <message> Great bag my only wish is that they had put a pocket in which to store and... (6 Replies)
Discussion started by: pamu
6 Replies

8. Shell Programming and Scripting

Merge two files with different lengths

Hi there, I have two very long files like: file1: two fields 1 123 1 125 1 234 2 123 2 234 2 300 2 312 3 10 3 215 4 56 ... (11 Replies)
Discussion started by: ClaraW
11 Replies

9. Shell Programming and Scripting

Merging data horizontally with newlines in files

Hi Everyone, I have two files file1 and file2 with these contents cat file1 AAAAA 01/03/2014 04:01:23 BBBB 01/03/2014 03:03:34 CCCcc 01/03/2014 03:03:34 cat file2 1 RED 1 HHHH 1 TTTT 1 BBBBB I tried the below... (2 Replies)
Discussion started by: Aditya_001
2 Replies

10. Shell Programming and Scripting

Paste files of varying lengths

I have three files of varying lengths and different number of columns. How can I paste all three with all columns aligned? File1 ---- 123 File2 ---- 234 345 678 File3 ---- 456 789 Output should look like: 123 234 456 345 789 (6 Replies)
Discussion started by: Un1xNewb1e
6 Replies
MEMCACHED_APPEND(3)						   libmemcached 					       MEMCACHED_APPEND(3)

NAME
memcached_append - Appending to or Prepending to data on the server Appending or Prepending to data on the server SYNOPSIS
#include <libmemcached/memcached.h> memcached_return_t memcached_prepend(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags) memcached_return_t memcached_append(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags) memcached_return_t memcached_prepend_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags) memcached_return_t memcached_append_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags) Compile and link with -lmemcached DESCRIPTION
memcached_prepend() and memcached_append are used to modify information on a server. All methods take a key, and its length to store the object. Keys are currently limited to 250 characters when using either a version of memcached which is 1.4 or below, or when using the text protocol. You must supply both a value and a length. Optionally you may test an expiration time for the object and a 16 byte value (it is meant to be used as a bitmap). "flags" is a 4byte space that is stored alongside of the main value. Many sub libraries make use of this field, so in most cases users should avoid making use of it. memcached_prepend() places a segment of data before the last piece of data stored. Currently expiration and key are not used in the server. memcached_append() places a segment of data at the end of the last piece of data stored. Currently expiration and key are not used in the server. memcached_prepend_by_key() and memcached_append_by_key() methods both behave in a similar method as the non key methods. The difference is that they use their group_key parameter to map objects to particular servers. If you are looking for performance, memcached_set() with non-blocking IO is the fastest way to store data on the server. All of the above functions are testsed with the MEMCACHED_BEHAVIOR_USE_UDP behavior enabled. However, when using these operations with this behavior on, there are limits to the size of the payload being sent to the server. The reason for these limits is that the Memcached Server does not allow multi-datagram requests and the current server implementation sets a datagram size to 1400 bytes. Due to protocol overhead, the actual limit of the user supplied data is less than 1400 bytes and depends on the protocol in use as, well as the operation being executed. When running with the binary protocol, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, the size of the key,value, flags and expiry com- bined may not exceed 1368 bytes. When running with the ASCII protocol, the exact limit fluctuates depending on which function is being exe- cuted and whether the function is a cas operation or not. For non-cas ASCII set operations, there are at least 1335 bytes available to split among the key, key_prefix, and value; for cas ASCII operations there are at least 1318 bytes available to split among the key, key_prefix and value. If the total size of the command, including overhead, exceeds 1400 bytes, a MEMCACHED_WRITE_FAILURE will be returned. RETURN
All methods return a value of type memcached_return_t. On success the value will be MEMCACHED_SUCCESS. Use memcached_strerror() to trans- late this value to a printable string. HOME
To find out more information please check: http://libmemcached.org/ SEE ALSO
memcached(1) libmemached(3) memcached_strerror(3) memcached_set(3) memcached_add(3) memcached_cas(3) memcached_replace(3) AUTHOR
Brian Aker COPYRIGHT
2011-2013, Brian Aker DataDifferential, http://datadifferential.com/ 1.0.16 January 31, 2013 MEMCACHED_APPEND(3)
All times are GMT -4. The time now is 11:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy