Sponsored Content
Full Discussion: Adding missing lines in file
Top Forums UNIX for Dummies Questions & Answers Adding missing lines in file Post 302770127 by TheTransporter on Thursday 14th of February 2013 02:15:06 PM
Old 02-14-2013
Adding missing lines in file

Dear all,

I have a file with two columns - the first column is increasing every 50, the second column is just count (e.g. 5). However, when count is zero, no line is present.

Sample:

Quote:
1950 7
2000 14
2050 7
2100 13
2150 10
2200 9
2250 7
2300 8
2350 7
2400 4
2450 5
...
6550 1
6600 2
7050 1
7150 1
How can I change the file so as to include lines with zero count? e.g. in the previous file to put between the bold numbers

Quote:
6600 2
6650 0
6700 0
6750 0
6800 0
6850 0
6900 0
6950 0
7000 0
7050 1
7100 0
7150 1
How can I do it?

Thanks

---------- Post updated at 02:15 PM ---------- Previous update was at 01:35 PM ----------

basically I made a column file with all +50 numbers of column 1 and I wrote the code that seems it works:

Code:
for i in `cat columns`

do

        OUTPUT=$(grep "^$i" bound-char-rim.res)


if [ "${OUTPUT}" == "" ]; then
  echo $i 0
else
  echo $OUTPUT
fi

done

and then I take only columns 1 and 2.

Is there a better way?

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

adding text to a file between lines

Suppose content of my first file: first line second line third line How can i insert text between "first line" & "second Iline" Any help?????/ (7 Replies)
Discussion started by: bishweshwar
7 Replies

2. UNIX for Dummies Questions & Answers

Adding lines and columns to a file

Hi everybody, I've got two simples file1 like: aaa aaa aaa bbb bbb bbb ccc ccc ccc and file2 like: 111 111 111 222 222 222 333 333 333 I need to: 1) add a line say "new line" as the first line of the file 2)add a column from file2 (say column3) to file1; the new column should... (14 Replies)
Discussion started by: zajtat
14 Replies

3. Shell Programming and Scripting

Adding strings to lines in a file

Hi all, I have a positional text file that comes from some source application. Before it is processed by destination application I have to add some header (suffix) to every record(line) in the file. e.g. Actual File ............... AccountDetails AcNO Name Amount 1234 John 26578 5678... (3 Replies)
Discussion started by: sharath160
3 Replies

4. UNIX for Dummies Questions & Answers

Extracting lines present in one file but missing in another using Perl

Hey I have an input file containing a list of numbers like: U01120.CDS.1 D25328.CDS.1 X15573.CDS.1 K03515.CDS.1 L44140.CDS.10 U24183.CDS.1 M97347.CDS.1 U05259.CDS.1 And another input file containing results created on the basis of the above input: G6PT_HUMAN U01120.CDS.1 -1.9450 3.1706... (1 Reply)
Discussion started by: Banni
1 Replies

5. Shell Programming and Scripting

need to print the missing lines in 1 file from 1 file via script

Hi, I am writting a script which will take all the files present in 2 directories. (the 2 directories have the same files with same name but some different content) i need 2 compare 2 files and then copy the contents of file1 to file2. the contents which are missing in file1 and nothing from... (8 Replies)
Discussion started by: dazdseg
8 Replies

6. Shell Programming and Scripting

Adding new lines to a file + adding suffix to a pattern

I need some help with adding lines to file and substitute a pattern. Ok I have a file: #cat names.txt name: John Doe stationed: 1 name: Michael Sweets stationed: 41 . . . And would like to change it to: name: John Doe employed permanently stationed: 1-office (7 Replies)
Discussion started by: hemo21
7 Replies

7. Shell Programming and Scripting

join based on line number when one file is missing lines

I have a file that contains 87 lines, each with a set of coordinates (x & y). This file looks like: 1 200.3 -0.3 2 201.7 -0.32 ... 87 200.2 -0.314 I have another file which contains data that was taken at certain of these 87 positions. i.e.: 37 125 42 175 86 142 where the first... (1 Reply)
Discussion started by: jackiev
1 Replies

8. UNIX for Dummies Questions & Answers

Adding missing lines in file

Dear all, I have a file with two columns - the first column is increasing every 50, the second column is just count (e.g. 5). However, when count is zero, no line is present. Sample: 1950 7 2000 14 2050 7 2100 13 2150 10 2200 9 2250 7 2300 8 2350 7... (1 Reply)
Discussion started by: TheTransporter
1 Replies

9. Shell Programming and Scripting

Adding lines at a particular location in a file.

Hi Experts, Let us take a text file,say items.txt having the following data jar bottle gum tube cereal bag I want to add the content of items.txt to another file say #many lines not necessary ingredients #many line not necesary ingredients I want to append the data in... (3 Replies)
Discussion started by: Pradeep_1990
3 Replies

10. Shell Programming and Scripting

Adding lines to a large file

Hello, I have a relatively large text file (25,000K) consisting of records of data. For each record, I need to create a new line based on what is already there. Every record has a block that looks like, M END > <ID> 1 > <SOURCE> KEGG > <SOURCE_ID> C00002 > <NAME> ATP;... (4 Replies)
Discussion started by: LMHmedchem
4 Replies
HISTO(1)						      General Commands Manual							  HISTO(1)

NAME
histo - compute 1-dimensional histogram of N data columns SYNOPSIS
histo [-c][-p] xmin xmax nbins histo [-c][-p] imin imax DESCRIPTION
Histo bins columnular data on the standard input between the given minimum and maximum values. If three command line arguments are given, the third is taken as the number of data bins between the first two real numbers. If only two arguments are given, they are both assumed to be integers, and the number of data bins will be equal to their difference plus one. The bins are always of equal size. The output is N+1 columns of data (for N columns input), where the first column is the centroid of each division, and each row corresponds to the frequencies for each column around that value. If the -c option is present, then histo computes the cumulative histogram for each column instead of the straight frequencies. The upper value of each bin is printed also instead of the centroid. This may be useful in computing percentiles, for example. Values below the minimum specified are still counted in the cumulative total. The -p option tells histo to report the percentage of the total number of input lines rather than the absolute counts. In the case of a cumulative total, this yields the percentile values directly. Values above the maximum are counted as well as values below in this case. All input data is interpreted as real values, and columns must be white-space separated. If any value is less than the minimum or greater than the maximum, it will be ignored unless the -c option is specified. EXAMPLE
To count data values between -1 and 1 in 50 bins: histo -1 1 50 < input.dat To count frequencies of integers between 0 and 255: histo 0 255 < input.dat AUTHOR
Greg Ward SEE ALSO
cnt(1), neaten(1), rcalc(1), rlam(1), tabfunc(1), total(1) RADIANCE
9/6/96 HISTO(1)
All times are GMT -4. The time now is 03:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy