Sponsored Content
Top Forums Shell Programming and Scripting AWK Compare previous value with current. Post 302509246 by dikesm on Wednesday 30th of March 2011 10:56:59 AM
Old 03-30-2011
AWK Compare previous value with current.

Hi,
I have one small doubt how to go ahead and process the below requirement.

File Content
Code:
1,abc,10
2,xyz,11
3,pqr,12
4,pqr,13
5,pqr,14

Output file expected:
Code:
1,mnq,1
1,ddd,2
1,qqq,3
1,sss,4
1,ddd,5
1,eee,6
1,fff,7
1,ddr,8
1,rrd,9
1,der,10
2,dwe,11
3,pqr,12
4,pqr,12
5,pqr,12
12,adhe,0
13,add,1
.
.
.
.
.
.
.

thousands of records

Note that the pqr is repeated 3 times in this case for the 3rd column we have the the 3rd column value of the 1st occurence of pqr copied for the 2nd and 3 occurenct
i.e 4,pqr,13 gets changed to 4,pqr,12
and 5,pqr,14 gets changed to 5,pqr,12

Once the output file is generated then
then i want something like
Code:
cat 1 >10
cat 2>11
cat 3 4 5 > 12

I want this to be done dynamically since the number of records might be in thousands atleast

Would appreciate if we can an awk solution for the same.

Regards,
Dikesh Shah
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 03-30-2011 at 12:13 PM.. Reason: code tags, please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

2. UNIX for Advanced & Expert Users

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

3. UNIX for Dummies Questions & Answers

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

4. Shell Programming and Scripting

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (3 Replies)
Discussion started by: yerruhari
3 Replies

5. UNIX for Dummies Questions & Answers

Awk to print data from current and previous line

Hi guys, I have found your forum super useful. However, right now I am stuck on a seemingly "simple" thing in AWK. I have two columns of data, the first column in Age (in million years) and the second column is Convergence Rate (in mm/yr). I am trying to process my data so I can use it to... (2 Replies)
Discussion started by: awk_noob_456
2 Replies

6. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

7. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

8. Shell Programming and Scripting

Perl to send previous and current value

For example, I have a file called number.txt. x y 1 1 2 4 3 9 4 6 5 5 6 6 7 9 8 4 9 1 10 0 ... And I want to print out the value of x and y, if y%4==0 and the next value of y%4==0. Thus, the sample output is: 1 1 *because the previous x before 2 is 1 2 4 *because 4%4 == 0 7 9... (2 Replies)
Discussion started by: Tzeronone
2 Replies

9. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

10. Shell Programming and Scripting

How to compare previous and current item in for loop in bash?

Hey, I am trying to compare formated login and logout dates from one user at a host which I have stored in a tmp directory in order to find out the total login time. I need to compare them in order to find overlapping intervals. At first I tried to store each log in and logo date in an array... (3 Replies)
Discussion started by: Mumu123
3 Replies
editconf(1)					 GROMACS suite, VERSION 4.5.4-dev-20110404-bc5695c				       editconf(1)

NAME
editconf - edits the box and writes subgroups VERSION 4.5.4-dev-20110404-bc5695c SYNOPSIS
editconf -f conf.gro -n index.ndx -o out.gro -mead mead.pqr -bf bfact.dat -[no]h -[no]version -nice int -[no]w -[no]ndef -bt enum -box vec- tor -angles vector -d real -[no]c -center vector -aligncenter vector -align vector -translate vector -rotate vector -[no]princ -scale vec- tor -density real -[no]pbc -resnr int -[no]grasp -rvdw real -sig56 real -[no]vdwread -[no]atom -[no]legend -label string -[no]conect DESCRIPTION
editconf converts generic structure format to .gro, .g96 or .pdb. The box can be modified with options -box, -d and -angles. Both -box and -d will center the system in the box, unless -noc is used. Option -bt determines the box type: triclinic is a triclinic box, cubic is a rectangular box with all sides equal dodecahedron repre- sents a rhombic dodecahedron and octahedron is a truncated octahedron. The last two are special cases of a triclinic box. The length of the three box vectors of the truncated octahedron is the shortest distance between two opposite hexagons. Relative to a cubic box with some periodic image distance, the volume of a dodecahedron with this same periodic distance is 0.71 times that of the cube, and that of a truncated octahedron is 0.77 times. Option -box requires only one value for a cubic, rhombic dodecahedral, or truncated octahedral box. With -d and a triclinic box the size of the system in the x-, y-, and z-directions is used. With -d and cubic, dodecahedron or octahedron boxes, the dimensions are set to the diameter of the system (largest distance between atoms) plus twice the specified distance. Option -angles is only meaningful with option -box and a triclinic box and cannot be used with option -d. When -n or -ndef is set, a group can be selected for calculating the size and the geometric center, otherwise the whole system is used. -rotate rotates the coordinates and velocities. -princ aligns the principal axes of the system along the coordinate axes, with the longest axis aligned with the x-axis. This may allow you to decrease the box volume, but beware that molecules can rotate significantly in a nanosecond. Scaling is applied before any of the other operations are performed. Boxes and coordinates can be scaled to give a certain density (option -density). Note that this may be inaccurate in case a .gro file is given as input. A special feature of the scaling option is that when the factor -1 is given in one dimension, one obtains a mirror image, mirrored in one of the planes. When one uses -1 in three dimensions, a point-mirror image is obtained. Groups are selected after all operations have been applied. Periodicity can be removed in a crude manner. It is important that the box vectors at the bottom of your input file are correct when the periodicity is to be removed. When writing .pdb files, B-factors can be added with the -bf option. B-factors are read from a file with with following format: first line states number of entries in the file, next lines state an index followed by a B-factor. The B-factors will be attached per residue unless an index is larger than the number of residues or unless the -atom option is set. Obviously, any type of numeric data can be added instead of B-factors. -legend will produce a row of CA atoms with B-factors ranging from the minimum to the maximum value found, effec- tively making a legend for viewing. With the option -mead a special .pdb ( .pqr) file for the MEAD electrostatics program (Poisson-Boltzmann solver) can be made. A further prerequisite is that the input file is a run input file. The B-factor field is then filled with the Van der Waals radius of the atoms while the occupancy field will hold the charge. The option -grasp is similar, but it puts the charges in the B-factor and the radius in the occupancy. Option -align allows alignment of the principal axis of a specified group against the given vector, with an optional center of rotation specified by -aligncenter. Finally, with option -label, editconf can add a chain identifier to a .pdb file, which can be useful for analysis with e.g. Rasmol. To convert a truncated octrahedron file produced by a package which uses a cubic box with the corners cut off (such as GROMOS), use: editconf -f in -rotate 0 45 35.264 -bt o -box veclen -o out where veclen is the size of the cubic box times sqrt(3)/2. FILES
-f conf.gro Input Structure file: gro g96 pdb tpr etc. -n index.ndx Input, Opt. Index file -o out.gro Output, Opt. Structure file: gro g96 pdb etc. -mead mead.pqr Output, Opt. Coordinate file for MEAD -bf bfact.dat Input, Opt. Generic data file OTHER OPTIONS
-[no]hno Print help info and quit -[no]versionno Print version info and quit -nice int 0 Set the nicelevel -[no]wno View output .xvg, .xpm, .eps and .pdb files -[no]ndefno Choose output from default index groups -bt enum triclinic Box type for -box and -d: triclinic, cubic, dodecahedron or octahedron -box vector 0 0 0 Box vector lengths (a,b,c) -angles vector 90 90 90 Angles between the box vectors (bc,ac,ab) -d real 0 Distance between the solute and the box -[no]cno Center molecule in box (implied by -box and -d) -center vector 0 0 0 Coordinates of geometrical center -aligncenter vector 0 0 0 Center of rotation for alignment -align vector 0 0 0 Align to target vector -translate vector 0 0 0 Translation -rotate vector 0 0 0 Rotation around the X, Y and Z axes in degrees -[no]princno Orient molecule(s) along their principal axes -scale vector 1 1 1 Scaling factor -density real 1000 Density (g/L) of the output box achieved by scaling -[no]pbcno Remove the periodicity (make molecule whole again) -resnr int -1 Renumber residues starting from resnr -[no]graspno Store the charge of the atom in the B-factor field and the radius of the atom in the occupancy field -rvdw real 0.12 Default Van der Waals radius (in nm) if one can not be found in the database or if no parameters are present in the topology file -sig56 real 0 Use rmin/2 (minimum in the Van der Waals potential) rather than sigma/2 -[no]vdwreadno Read the Van der Waals radii from the file vdwradii.dat rather than computing the radii based on the force field -[no]atomno Force B-factor attachment per atom -[no]legendno Make B-factor legend -label string A Add chain label for all residues -[no]conectno Add CONECT records to a .pdb file when written. Can only be done when a topology is present KNOWN PROBLEMS
- For complex molecules, the periodicity removal routine may break down, in that case you can use trjconv. SEE ALSO
gromacs(7) More information about GROMACS is available at <http://www.gromacs.org/>. Mon 4 Apr 2011 editconf(1)
All times are GMT -4. The time now is 04:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy