Re: processing more than two files...



nag wrote:
On Feb 21, 10:01 pm, Janis Papanagnou <janis_papanag...@xxxxxxxxxxx>
wrote:

nag wrote:

On Feb 18, 10:21 pm, Hermann Peifer <pei...@xxxxxx> wrote:

nag wrote:

I have files (fl1,fl2,fl3,fl4,fl5,fl6) like mentioned below. I want to
join all the files on field 1 with delimiter as "|".

I can do it using join command, but it will take only 2 files at a
time...is there any awkway to solve this.

00039654 |4|380000
00216654 |6|405000
00242670 |2|200000
00961654 |7|535000
00998654 |14|1550000
01090654 |68|5040000
01106654 |13|545000
01112654 |120|8515000
01140654 |99|7770000
01187654 |58|4470000
01199654 |53|22220000
01205654 |54|9595000
01216654 |20|1025000

Try this for a start:
awk '{a[$1] = a[$1] $2}END{for (i in a) print i, a[i]}' yourfiles

hermann

Herman sir,
Is there any different type of solution for this....? Here my file is
having "|" as FS, if it has space as FS then also we have to
concatenate the $1 and $2? I am little bit confused. Sorry for
bothering you.

What is that blank after the first field in your data? If it's always
there Herman's solution should work fine as it is without changing the
FS. If your data looks different from what you posted provide accurate
new data to be able to understand what your problem is.

For example if you data entries look like 00242670 2 200000 then you
have to concatenate $2 and $3 to a[$1].
Or if your data entries look like that 00242670|2|200000 then you'd
in addition set the FS to "|".
Just some guesses.

Janis


First field of my data has maximum 9 characters and minimum 8
characters. It is like this..Here when i define FS="|" it's not giving
any result. If I keep a space between first field and field separater
(|) then Herman's solution is giving expected result....

00039654 |4|380000
00216654 |6|405000
00242670 |2|200000
00961654 |7|535000
00998654 |14|1550000
009851011|7|10000
012511011|8|500000

Okay, then the simplest solution is to use GNU awk and its fieldwidths
feature (that will keep the rest of the program as it is)...

gawk 'BEGIN {FIELDWIDTHS = "9 120"}
{a[$1] = a[$1] $2}
END {for (i in a) print i, a[i]}
' yourfiles

You can of course replace that GNU specific feature by operating on the
substrings of $0 to use with other awks...

awk '{s1=substr($0,1,9); s2=substr($0,10); a[s1] = a[s1] s2}
END {for (i in a) print i, a[i]}
' yourfiles


Janis
.



Relevant Pages

  • Re: Looking for other themes in anime (and manga, if youd like)
    ... visitors could ask about anime series, OAVs and manga/doujinshi that featured other themes, character types and/or storylines. ... How many anime and/or manga feature the 'traditional' pantaloon-clad, wish-granting genie? ... dressed up as American characters (Shinobu as Wonder Woman, ...
    (rec.arts.anime.misc)
  • Re: Looking for other themes in anime (and manga, if youd like)
    ... How many anime and/or manga feature the 'traditional' pantaloon-clad, ... I know that there was one in the anime series, Gokudo, that changed his ... the characters, not a temple guardian). ...
    (rec.arts.anime.misc)
  • Re: Combo Box selection populates text box
    ... Put the phase value strings into the first field, ... of carriage return and line feed characters) by pressing Ctrl+Enter when ... Private Sub Phase_AfterUpdate ... My attempt was to use an external word doc for these long phase details. ...
    (microsoft.public.access.forms)
  • Re: Why is my merge data being truncated?
    ... Is this what you would call a feature of Word or a limitation or a problem. ... characters appeared instead of the full data. ... >>ODBC option mimicked the OLE option, but the Converter ...
    (microsoft.public.office.misc)
  • get(char*, num, delim) question
    ... different object based upon the characters in the first field. ... " invalid conversion from `char*' to `char'" ... dealing with the getproblem. ...
    (comp.lang.cpp)