Re: processing more than two files...
- From: Janis Papanagnou <janis_papanagnou@xxxxxxxxxxx>
- Date: Mon, 23 Feb 2009 18:44:01 +0100
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
.
- References:
- processing more than two files...
- From: nag
- Re: processing more than two files...
- From: Hermann Peifer
- Re: processing more than two files...
- From: nag
- Re: processing more than two files...
- From: Janis Papanagnou
- Re: processing more than two files...
- From: nag
- processing more than two files...
- Prev by Date: Re: processing more than two files...
- Next by Date: getline problem .
- Previous by thread: Re: processing more than two files...
- Next by thread: Re: processing more than two files...
- Index(es):
Relevant Pages
|