Sponsored Content
Special Forums Windows & DOS: Issues & Discussions Gawk on Windows: Joining lines only if 1st field matches Post 302626797 by M@LIK on Thursday 19th of April 2012 08:26:32 PM
Old 04-19-2012
Bug Gawk on Windows: Joining lines only if 1st field matches

Hi..
i have two files::
file_1::
Code:
mOnkey
huMAn

file_2::
Code:
Human:hates:banana
i:like:***
Monkey:loves:banana
dogs:kill:cats

desired output::
Code:
Monkey:loves:banana
Human:hates:banana

so only when the 1st field matches from both files print it from file_2 ((case-sensitive))



i also would like to know how to match different fields..
file_1::
Code:
AA:11
BB:22

file_2::
Code:
first:AA:2011
second:BB:2012

desired output::
Code:
first:AA:2011:11
second:BB:2012:22

so only if field1 from file_1 matches with field2 from file_2 print whole file_2 joined with field2 from the same line in file_1

i hope u understand my cheesy english : P THANKx in advance
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining columns from two files, if the key matches

I am trying to join/paste columns from two files for the rows with matching first field. Any help will be appreciated. Files can not be sorted and may not have all rows in both files. Thanks. File1 aaa 111 bbb 222 ccc 333 File2 aaa sss mmmm ccc kkkk llll ddd xxx yyy Want to... (1 Reply)
Discussion started by: sk_sd
1 Replies

2. Shell Programming and Scripting

Displaying lines of a file where the second field matches a pattern

Howdy. I know this is most likely possible using sed or awk or grep, most likely a combination of them together, but how would one go about running a grep like command on a file where you only try to match your pattern to the second field in a line, space delimited? Example: You are... (3 Replies)
Discussion started by: LordJezoX
3 Replies

3. UNIX for Dummies Questions & Answers

Joining lines of a text file using GAWK

sir... am having a data file of customer master., containing some important fields as a set one line after another., what i want is to have one set of these fields(rows) one after another in line.........then the second set... and so on... till the last set completed. ... (0 Replies)
Discussion started by: KANNI786
0 Replies

4. UNIX for Dummies Questions & Answers

JOINING MULTIPLE LINES IN A TEXT FILE USING GAWK

sir... am having a data file of customer master., containing some important fields as a set one line after another., what i want is to have one set of these fields(rows) one after another in line.........then the second set... and so on... till the last set completed. I WANT THE DATA... (0 Replies)
Discussion started by: KANNI786
0 Replies

5. Shell Programming and Scripting

adding field values if field matches

hi i have file as below , i want to add duplicate records like bell_bb to one record with valuve as 15 ( addition of both ) any oneline awk script to achive this ? header 0 CAMPAIGN_NAME 1 Bell_BB 14 Bell_MONTHLY 803 SOLO_UNBEATABLE 644 Bell_BB 1 Bell_MONTHLY 25 SOLO_UNBEATABLE... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

6. UNIX for Dummies Questions & Answers

join 2 lines based on 1st field

hi i have a file with the following lines 2303:13593:137135 16 abc1 26213806....... 1234:45675:123456 16 bbc1 9813806....... 2303:13593:137135 17 bna1 26566444.... 1234:45675:123456 18 nnb1 98123456....... i want to join the lines having common 1st field i,e., ... (1 Reply)
Discussion started by: anurupa777
1 Replies

7. Shell Programming and Scripting

Displaying the first field if the second field matches the pattern using Perl

Hi, I am trying with the below Perl command to print the first field when the second field matches the given pattern: perl -lane 'open F, "< myfile"; for $i (<F>) {chomp $i; if ($F =~ /patt$/) {my $f = (split(" ", $i)); print "$f";}} close F' dummy_file I know I can achieve the same with the... (7 Replies)
Discussion started by: royalibrahim
7 Replies

8. Shell Programming and Scripting

awk to remove lines in file if specific field matches

I am trying to remove lines in the target.txt file if $5 before the - in that file matches sorted_list. I have tried grep and awk. Thank you :). grep grep -v -F -f targets.bed sort_list grep -vFf sort_list targets awk awk -F, ' > FILENAME == ARGV {to_remove=1; next} > ! ($5 in... (2 Replies)
Discussion started by: cmccabe
2 Replies

9. Shell Programming and Scripting

Need to replace last field in a file,if first field matches

Hi, Need to replace last field in a file(/etc/passwd) ,if first filed matches with particular username. Scenario: cat testfor1 deekshi:x:7082:7082::/home/deekshi:/bin/bash harini1:x:7083:7083::/home/harini1:/bin/bash Here,if first field contains "deekshi", then i should replace... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

10. Shell Programming and Scripting

awk joining multiple lines based on field count

Hi Folks, I have a file with fields as follows which has last field in multiple lines. I would like to combine a line which has three fields with single field line for as shown in expected output. Please help. INPUT hname01 windows appnamec1eda_p1, ... (5 Replies)
Discussion started by: shunya
5 Replies
NCBO(1) 						      General Commands Manual							   NCBO(1)

NAME
ncbo - netCDF Binary Operator SYNTAX
ncbo [-3] [-4] [-6] [-A] [-C] [-c] [-D dbg] [-d dim,[ min][,[ max]]] [-F] [-h] [-L dfl_lvl] [-l path] [-O] [-p path] [-R] [-r] [-t thr_nbr] [-v var[,...]] [-X box] [-x] file_1 file_2 file_3 DESCRIPTION
ncbo subtracts variables in file_2 from the corresponding variables (those with the same name) in file_1 and stores the results in file_3. Variables in file_2 are broadcast to conform to the corresponding variable in file_1 if necessary. Broadcasting a variable means creating data in non-existing dimensions from the data in existing dimensions. For example, a two dimensional variable in file_2 can be subtracted from a four, three, or two (but not one or zero) dimensional variable (of the same name) in file_1. This functionality allows the user to compute anomalies from the mean. Note that variables in file_1 are not broadcast to conform to the dimensions in file_2. Thus, ncbo, the number of dimensions, or rank, of any processed variable in file_1 must be greater than or equal to the rank of the same variable in file_2. Furthermore, the size of all dimensions common to both file_1 and file_2 must be equal. When computing anomalies from the mean it is often the case that file_2 was created by applying an averaging operator to a file with the same dimensions as file_1, if not file_1 itself. In these cases, creating file_2 with ncra rather than ncwa will cause the ncbo operation to fail. For concreteness say the record dimension in file_1 is time. If file_2 were created by averaging file_1 over the time dimension with the ncra operator rather than with the ncwa operator, then file_2 will have a time dimension of size 1 rather than having no time dimension at all In this case the input files to ncbo, file_1 and file_2, will have unequally sized time dimensions which causes ncbo to fail. To prevent this from occuring, use ncwa to remove the time dimension from file_2. An example is given below. ncbo will never difference coordinate variables or variables of type NC_CHAR or NC_BYTE. This ensures that coordinates like (e.g., lati- tude and longitude) are physically meaningful in the output file, file_3. This behavior is hardcoded. ncbo applies special rules to some NCAR CSM fields (e.g., ORO). See NCAR CSM Conventions for a complete description. Finally, we note that ncflint (ncflint netCDF File Interpolator) can be also perform file subtraction (as well as addition, multiplication and interpolation). EXAMPLES
Say files 85_0112.nc and 86_0112.nc each contain 12 months of data. Compute the change in the monthly averages from 1985 to 1986: ncbo 86_0112.nc 85_0112.nc 86m85_0112.nc The following examples demonstrate the broadcasting feature of ncbo. Say we wish to compute the monthly anomalies of T from the yearly average of T for the year 1985. First we create the 1985 average from the monthly data, which is stored with the record dimension time. ncra 85_0112.nc 85.nc ncwa -O -a time 85.nc 85.nc The second command, ncwa, gets rid of the time dimension of size 1 that ncra left in 85.nc. Now none of the variables in 85.nc has a time dimension. A quicker way to accomplish this is to use ncwa from the beginning: ncwa -a time 85_0112.nc 85.nc We are now ready to use ncbo to compute the anomalies for 1985: ncbo -v T 85_0112.nc 85.nc t_anm_85_0112.nc Each of the 12 records in t_anm_85_0112.nc now contains the monthly deviation of T from the annual mean of T for each gridpoint. Say we wish to compute the monthly gridpoint anomalies from the zonal annual mean. A zonal mean is a quantity that has been averaged over the longitudinal (or x) direction. First we use ncwa to average over longitudinal direction lon, creating xavg_85.nc, the zonal mean of 85.nc. Then we use ncbo to subtract the zonal annual means from the monthly gridpoint data: ncwa -a lon 85.nc xavg_85.nc ncbo 85_0112.nc xavg_85.nc tx_anm_85_0112.nc Assuming 85_0112.nc has dimensions time and lon, this example only works if xavg_85.nc has no time or lon dimension. As a final example, say we have five years of monthly data (i.e., 60 months) stored in 8501_8912.nc and we wish to create a file which con- tains the twelve month seasonal cycle of the average monthly anomaly from the five-year mean of this data. The following method is just one permutation of many which will accomplish the same result. First use ncwa to create the file containing the five-year mean: ncwa -a time 8501_8912.nc 8589.nc Next use ncbo to create a file containing the difference of each month's data from the five-year mean: ncbo 8501_8912.nc 8589.nc t_anm_8501_8912.nc Now use ncks to group the five January anomalies together in one file, and use ncra to create the average anomaly for all five Januarys. These commands are embedded in a shell loop so they are repeated for all twelve months: foreach idx (01 02 03 04 05 06 07 08 09 10 11 12) ncks -F -d time,,,12 t_anm_8501_8912.nc foo. ncra foo. t_anm_8589_.nc end Note that ncra understands the stride argument so the two commands inside the loop may be combined into the single command ncra -F -d time,,,12 t_anm_8501_8912.nc foo. Finally, use ncrcat to concatenate the 12 average monthly anomaly files into one twelve-record file which contains the entire seasonal cycle of the monthly anomalies: ncrcat t_anm_8589_??.nc t_anm_8589_0112.nc AUTHOR
NCO manual pages written by Charlie Zender and Brian Mays. REPORTING BUGS
Report bugs to <http://sf.net/bugs/?group_id=3331>. COPYRIGHT
Copyright (C) 1995-2010 Charlie Zender This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for NCO is maintained as a Texinfo manual called the NCO User's Guide. Because NCO is mathematical in nature, the documentation includes TeX-intensive portions not viewable on character-based displays. Hence the only complete and authoritative versions of the NCO User's Guide are the PDF (recommended), DVI, and Postscript versions at <http://nco.sf.net/nco.pdf>, <http://nco.sf.net/nco.dvi>, and <http://nco.sf.net/nco.ps>, respectively. HTML and XML versions are available at <http://nco.sf.net/nco.html> and <http://nco.sf.net/nco.xml>, respectively. If the info and NCO programs are properly installed at your site, the command info nco should give you access to the complete manual, except for the TeX-intensive portions. HOMEPAGE
The NCO homepage at <http://nco.sf.net> contains more information. NCBO(1)
All times are GMT -4. The time now is 10:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy