Sponsored Content
Top Forums Shell Programming and Scripting Merge and Sort tabular data from different text files Post 302957780 by RavinderSingh13 on Thursday 15th of October 2015 01:46:18 AM
Old 10-15-2015
Hello Syeda,

For file1 and file2, could you please try following and let me know if this helps.
Code:
awk 'BEGIN{print "     file1 file2"}FNR==NR{;A[$1]=$NF;next} ($1 in A){print $1 OFS A[$1] OFS $NF} !($1 in A){print $1 OFS "-" OFS $NF}' file1 file2 | sort -k1,3

Output will be as follows.
Code:
     file1 file2
H-01 23 17
H-02 14 43
H-03 5 7
H-04 - 7
H-05 9 8
H-224 - 8

Please do let us know if you have any queries on same.

Thanks,
R. Singh

Last edited by RavinderSingh13; 10-15-2015 at 02:52 AM..
This User Gave Thanks to RavinderSingh13 For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies

2. Shell Programming and Scripting

Merge 70 files into one data matrix

Hi, I have a list of 70 files in a directory and I need to merge the content of each file into one big matrix file (71 columns x 3060 rows). Each file has the following format only two columns per file: unique identifier1 randomtext1 randomtext1 a 5 b 3 c 6 d 3 e 2... (11 Replies)
Discussion started by: labrazil
11 Replies

3. AIX

merge text files

Hello. Could you please help to know the command to merge multiple text files into one? I am thinking to use: cat f1.txt f2.txt f3.txt > f4.txt Is it okay to use cat command for same purpose - Or could there be any disadvantage in using it? Thank you (4 Replies)
Discussion started by: panchpan
4 Replies

4. UNIX for Dummies Questions & Answers

Merge files and sort them

hi all, i have three files naming file1 , file2, file3 . i want to merge the content of these three files, sort them and display the sorted output on the screen page by page. (1 Reply)
Discussion started by: sonu_pal
1 Replies

5. Shell Programming and Scripting

AWK to match and merge data from 2 files into 1.

Hello, hopefully this is an easy on for the AWK guru's out there. I'm having some trouble figuring out how to match+merge data in 2 files into 1 single report. I've got my 2 files filtered and delimited, just need to MATCH $3 in file1 to $1 in file2, then put $0 from File1 and $2+$3 from File2... (6 Replies)
Discussion started by: right_coaster
6 Replies

6. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

7. Shell Programming and Scripting

Extract data in tabular format from multiple files

Hi, I have directory with multiple files from which i need to extract portion of specif lines and insert it in a new file, the new file will contain a separate columns for each file data. Example: I need to extract Value_1 & Value_3 from all files and insert in output file as below: ... (2 Replies)
Discussion started by: belalr
2 Replies

8. UNIX for Dummies Questions & Answers

Merge two text files (oh no, not again!)

Hello, I'm new to this forum. I have always made good use of all the wise hints shown here. But this time I'm struggling with an issue that is driving me crazy. I have two text files, I have to merge them based on the first column, resulting file must contain all record from the first file... (4 Replies)
Discussion started by: emare
4 Replies

9. Shell Programming and Scripting

Sort data in text file in particular format

I have to sort below output in text file in unix bash 20170308 DA,I,113 20170308 PM,I,123 20170308 DA,U,22 20170308 PM,U,123 20170309 DA,I,11 20170309 PM,I,23 20170309 DA,U,123 20170309 PM,U,233 (8 Replies)
Discussion started by: Adfire
8 Replies
tbl-dctrl(1)						   Debian administrator's manual					      tbl-dctrl(1)

NAME
tbl-dctrl - generate tabular representations of data in dctrl format SYNOPSIS
tbl-dctrl [ options ] [ -c column-specification ... ] [ filename ] ... tbl-dctrl --version tbl-dctrl --help DESCRIPTION
tbl-dctrl creates tabular representations of data given to it in Debian control file format. By default, tbl-dctrl reads the whole database, looking for the longest entry in each requested column; it then outputs a table, with bor- ders and column titles, where each column is just wide enough to fit the longest entry. Most of this behaviour can be customized as described below. A column is requested by specifying the -c (--column) switch with a column specification. The simplest kind of a column specification con- sists solely of the name of a field. In such a case, tbl-dctrl will include in the output a column whose title is the literal column spec- ification and whose data is drawn from fields with that name. If no -c options are given, tbl-dctrl will use all fields in the input in the order in which they first appear. There are two optional additions one can make to a column specification. Prefixing the field name with some text followed by an equality sign (for example, -c 'Package name=Package') modifies the column in such a way that the text before the equality sign is used as the col- umn title, while the text after the equality sign is used as the name of the field from which data is drawn. One can also append a colon followed by a positive whole number to the field name. In such a case, the number after the colon specifies the width of the column. These two additions can be used separately or together. If there are more than one colon, the last one is significant. If there are more than one equals sign, the first one is significant. Other colons and equals signs are used simply as data. Note that the whole column specification must be given to tbl-dctrl as one argument, so if it contains spaces, it must be quoted for the shell. If all requested columns have a specified width, tbl-dctrl will produce output immediately, not waiting for the whole input to be read in. OPTIONS
-d delimiter, --delimiter=delimiter Instead of drawing nice borders to the table, use the specified delimiter string to delimit columns in a row. -H, --no-heading Do not print a table heading (column titles). -l level, --errorlevel=level Set log level to level. level is one of fatal, important, informational and debug, but the last may not be available, depending on the compile-time options. These categories are given here in order; every message that is emitted when fatal is in effect, will be emitted in the important error level, and so on. The default is important. -V, --version Print out version information. -C, --copying Print out the copyright license. This produces much output; be sure to redirect or pipe it somewhere (such as your favourite pager). -h, --help Print out a help summary. OPERANDS
tbl-dctrl will read its input from the files named on the command line, in the specified order. A file called - represents the program's standard input stream. If no files are named, the program behaves as if - alone had been named, that is, input is read from the standard input stream. STDIN
The standard input stream may be used as input as specified above in the OPERANDS section. INPUT FILES
All input to tbl-dctrl is in the format of a Debian control file. A Debian control (dctrl) file is a semistructured single-table database stored in a machine-parseable text file. Such a database consists of a set of records; each record is a mapping from field names to field content. Textually, records are separated by empty lines, while each field is encoded as one or more nonempty lines inside a record. A field starts with its name, followed by a colon, followed by the field content. The colon must reside on the first line of the field, and the first line must start with no whitespace. Subsequent lines, in contrast, always start with linear whitespace (one or more space or tab characters). When input is read from multiple files, a record separator is implicit between two adjacent files. ENVIRONMENT VARIABLES
The standard locale environment, specifically its character set setting, affects the interpretation of input and output as character streams. ASYNCHRONOUS EVENTS
Standard UNIX signals have their usual meaning. STDOUT
All output is sent to the standard output stream. The output is a tabular representation of the input database restricted to the specified fields. Logically, the output is a table; when the -d option is used, this table is represented simply by separating columns in each row by the specified delimiter; when the option is not used, a frame is drawn around the table. The order of the columns is the same as the order of the column specifications on the command line. OUTPUT FILES
There are no output files. EXIT STATUS
This utility exits with 0 when successful. It uses a nonzero exit code inconsistently when an error is noticed (this is a bug). CONSEQUENCES OF ERRORS
In case of errors in the input, the output will be partially or completely garbage. In case of errors in invocation, the program will refuse to function. EXAMPLES
The following command line pipe outputs a table of all packages, with their maintainer data, sorted by the maintainer data, that have no content: % grep-available -FInstalled-Size --eq 0 | sort-dctrl -kMaintainer - | tbl-dctrl -cPackage -cMaintainer AUTHOR
The tbl-dctrl program and this manual page were written by Antti-Juhani Kaijanaho. SEE ALSO
apt-cache(1), ara(1), dpkg-awk(1), dpkg-query(1), grep-dctrl(1), sort-dctrl(1), dpkg(8) Debian Project 2006-04-02 tbl-dctrl(1)
All times are GMT -4. The time now is 05:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy