Sponsored Content
Top Forums Shell Programming and Scripting count numbers of matching rows and replace its value in another file Post 302375519 by GoldenFalcon10 on Saturday 28th of November 2009 05:56:42 AM
Old 11-28-2009
count numbers of matching rows and replace its value in another file

Hello all,
can you help me in this problem, assume We have two txt file (file_1 and file_3) one is file_1 contains the data:

a 0
b 1
c 3
a 7
b 4
c 5
b 8
d 6
.
.
.
.
and I need to count the lines with the matching data (a,b,..) and print in new file called file_2 such as the output:

a 2
b 3
c 2
d 1

the other file file_3 contains the data:

a A
b B
c C
d D
.
.
.
now i want two merge the two file to obtain the file format as shown:

A 2
B 3
C 2
D 1
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to replace one character by numbers in a file

suppose u have a file aas P-H 123 gdg O-U 223 hdy I-Y 12 fgd K-O 333 ssa L-P 32 output shud be like that aas P123H gdg O223U hdy I12Y fgd K333O ssa L32P thanks (7 Replies)
Discussion started by: cdfd123
7 Replies

2. AIX

How to replace many numbers with one number in a file

How to replace many numbers with one number in a file. Many numbers like 444565,454678,443298,etc. i want to replace these with one number (300).Please halp me out. (2 Replies)
Discussion started by: vpandey
2 Replies

3. Shell Programming and Scripting

How to replace rows from...to in a file?

Here is a description what i need: Document1: start... aaa bbb ccc ...end ======================= Document2: start... <paste the copied lines here> ...end All rows of document1 between "start...end" should be copied into the empty section "start...end" of document2. The... (3 Replies)
Discussion started by: smitty11
3 Replies

4. Shell Programming and Scripting

Grouping data numbers in a text file into prescribed intervals and count

I have a text file that contains numbers (listed from the smallest to the largest). For ex. 34 817 1145 1645 1759 1761 3368 3529 4311 4681 5187 5193 5199 5417 5682 . . (5 Replies)
Discussion started by: Lucky Ali
5 Replies

5. Shell Programming and Scripting

Delete rows based on line numbers in a file

I have to find the number of rows in a file and delete those many rows in another file. For example, if I have 3 rows in a file A, i have to delete first 3 rows in anothe file B, I have the code, it works as standalone, when I merge this with m application (c with unix), it doesnt work. ... (2 Replies)
Discussion started by: Muthuraj K
2 Replies

6. Shell Programming and Scripting

Extract rows from file based on row numbers stored in another file

Hi All, I have a file which is like this: rows.dat 1 2 3 4 5 6 3 4 5 6 7 8 7 8 9 0 4 3 2 3 4 5 6 7 1 2 3 4 5 6 I have another file with numbers like these (numbers.txt): 1 3 4 5 I want to read numbers.txt file line by line. The extract the row from rows.dat based on the... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

7. UNIX for Dummies Questions & Answers

Count of rows starting with 01 in a file

Hi I am very new to unix and please help me in solving the below problem I have a file with 50000+ rows. Each row(line) start with 01 or 02 or 03. Now i have to get the count of rows starting with 01 only, Thanks in advance (3 Replies)
Discussion started by: nmakkena
3 Replies

8. UNIX for Dummies Questions & Answers

Count rows in .dat file

Could you please tell e how to find the total number of rows in a .dat file. edit by bakunin: this is exactly why in "advanced and expert" section?? I transfer this thread to "Unix for Dummies Questions and Answers" (2 Replies)
Discussion started by: Deeptanshu
2 Replies

9. Shell Programming and Scripting

Replace a character of specified column(s) of all rows in a file

Hi - I have a file "file1" of below format. Its a comma seperated file. Note that each string is enclosed in double quotes. "abc","-0.15","10,000.00","IJK" "xyz","1,000.01","1,000,000.50","OPR" I want the result as: "abc","-0.15","10000.00","IJK" "xyz","1,000.01","1000000.50","OPR" I... (8 Replies)
Discussion started by: njny
8 Replies

10. Shell Programming and Scripting

Script Shell: Count The sum of numbers in a file

Hi all; Here is my file: V1.3=4 V1.4=5 V1.1=3 V1.2=6 V1.3=6 Please, can you help me to write a script shell that counts the sum of values in my file (4+5+3+6+6) ? Thank you so much for help. Kind regards. (3 Replies)
Discussion started by: chercheur111
3 Replies
DIFFSTAT(1)						      General Commands Manual						       DIFFSTAT(1)

NAME
diffstat - make histogram from diff-output SYNOPSIS
diffstat [options] [file-specifications] DESCRIPTION
This program reads the output of diff and displays a histogram of the insertions, deletions, and modifications per-file. Diffstat is a program that is useful for reviewing large, complex patch files. It reads from one or more input files which contain output from diff, producing a histogram of the total lines changed for each file referenced. If the input filename ends with .bz2, .gz, .lzma, .z or .Z, diffstat will read the uncompressed data via a pipe from the corresponding pro- gram. It also can infer the compression type from files piped via the standard input. Diffstat recognizes the most popular types of output from diff: unified preferred by the patch utility. context best for readability, but not very compact. default not good for much, but simple to generate. Diffstat detects the lines that are output by diff to tell which files are compared, and then counts the markers in the first column that denote the type of change (insertion, deletion or modification). These are shown in the histogram as "+", "-" and "!" characters. If no filename is given on the command line, diffstat reads the differences from the standard input. OPTIONS
-b ignore lines matching "Binary files XXX and YYY differ" in the diff -c prefix each line of output with "#", making it a comment-line for shell scripts. -D destination specify a directory containing files which can be referred to as the result of applying the differences. diffstat will count the lines in the corresponding files (after adjusting the names by the -p option) to obtain the total number of lines in each file. The remainder, after subtracting modified and deleted lines, is shown as "unchanged lines". -e file redirect standard error to file. -f format specify the format of the histogram. 0 for concise, which shows only the value and a single histogram code for each of insert (+), delete (-) or modify (!) 1 for normal output, 2 to fill in the histogram with dots, 4 to print each value with the histogram. Any nonzero value gives a histogram. The dots and individual values can be combined, e.g., -f6 gives both. -h prints the usage message and exits. -k suppress the merging of filenames in the report. -l lists only the filenames. No histogram is generated. -m merge insert/delete counts from each "chunk" of the patch file to approximate a count of the modified lines. -n number specify the minimum width used for filenames. If you do not specify this, diffstat uses the length of the longest filename, after stripping common prefixes. -N number specify the maximum width used for filenames. Names longer than this limit are truncated on the left. If you do not specify this, diffstat next checks the -n option. -o file redirect standard output to file. -p number override the logic that strips common pathnames, simulating the patch "-p" option. -q suppress the "0 files changed" message for empty diffs. -r code provides optional rounding of the data shown in histogram, rather than truncating with error adjustments. 0 is the default. No rounding is performed, but accumulated errors are added to following columns. 1 rounds the data 2 rounds the data and adjusts the histogram to ensure that it displays something if there are any differences even if those would normally be rounded to zero. -S source this is like the -D option, but specifies a location where the original files (before applying differences) can be found. -t overrides the histogram, generates output of comma separated values. -u suppress the sorting of filenames in the report. -v show progress, e.g., if the output is redirected to a file, write progress messages to the standard error. -V prints the current version number and exits. -w number specify the maximum width of the histogram. The histogram will never be shorter than 10 columns, just in case the filenames get too large. ENVIRONMENT
Diffstat runs in a portable UNIX(R) environment. You can override the compiled-in paths of programs used for decompressing input files by setting environment variables corresponding to their name: DIFFSTAT_BZCAT_PATH DIFFSTAT_BZIP2_PATH DIFFSTAT_COMPRESS_PATH DIFFSTAT_GZIP_PATH DIFFSTAT_LZCAT_PATH DIFFSTAT_PCAT_PATH DIFFSTAT_UNCOMPRESS_PATH DIFFSTAT_ZCAT_PATH However, diffstat assumes that the resulting program uses the same command-line options, e.g., "-c" to decompress to the standard output. FILES
Diffstat is a single binary module, which uses no auxiliary files. BUGS
Diffstat makes a lot of assumptions about the format of a diff file. There is no way to obtain a filename from the standard diff between two files with no options. Context diffs work, as well as unified diffs. There's no easy way to determine the degree of overlap between the "before" and "after" displays of modified lines. diffstat simply counts the number of inserted and deleted lines to approximate modified lines for the -m option. SEE ALSO
diff (1). AUTHOR
Thomas Dickey <dickey@invisible-island.net>. DIFFSTAT(1)
All times are GMT -4. The time now is 04:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy