![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| concatenate and display 2 lines as 1 with a condition for 2 line ? | vithala | Shell Programming and Scripting | 7 | 07-11-2008 01:01 AM |
| Need solution concatenate and display 2 lines as 1 with a condition for 2 line ? | vithala | UNIX for Advanced & Expert Users | 1 | 07-10-2008 01:27 PM |
| duplicate line in a text file | nixguy | Shell Programming and Scripting | 5 | 04-29-2008 02:19 AM |
| removing line and duplicate line | ocelot | UNIX for Dummies Questions & Answers | 11 | 01-30-2007 12:44 PM |
| how to concatenate two command in one line and get the display in one screen | vasikaran | UNIX for Dummies Questions & Answers | 9 | 07-01-2005 05:41 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi All,
i have a zip file like the format 794051400123|COM|24|0|BD|R|99.98 794051413727|COM|11|0|BD|R|28.99 794051415622|COM|23|0|BD|R|28.99 883929004676|COM|0|0|BD|R|28.99 794051400123|MOM|62|0|BD|R|99.98 794051413727|MOM|4|0|BD|R|28.99 794051415622|MOM|80|0|BD|R|28.99 883929004676|MOM|0|0|BD|R|28.99 883929017164|MOM|0|0|BD|R|39.99 794051400123|RNO|73|0|BD|R|99.98 794051413727|RNO|8|0|BD|R|28.99 794051415622|RNO|84|0|BD|R|28.99 883929004676|RNO|0|0|BD|R|28.99 794051400123|SOM|25|0|BD|R|99.98 794051415622|SOM|80|0|BD|R|28.99 883929004676|SOM|0|0|BD|R|28.99 883929017164|SOM|0|0|BD|R|39.99 ................................. i need concate all duplicate line like 794051400123|COM|24|MOM|62|SOM|25|RNO|73 794051413727|COM|11||MOM|4|RNO|8 ............ ... the file size is nearly 30 MB.So it takes lot of time.I have to do it with in 15 min. please help me. Thanks! vaskar |
|
||||
|
Tested and working.
Code:
#!/usr/bin/env python
import sys
input = open(sys.argv[1], 'r')
dict = {}
for line in input:
line = line.rstrip()
if line.count("|"):
line = line.split("|")
if dict.has_key(line[0]):
dict[line[0]].extend(line[1:3])
else:
dict[line[0]] = line[1:3]
input.close()
for key, value in dict.items():
print("%s|%s" % (key, "|".join(value)))
|
|
||||
|
Gift horse and all that ...
Assuming you mean take all values with an identical first field, and paste together fields 2 and 3 from all those lines, something like Code:
sort file |
awk -F '|' '$1 == prev { collect=collect "|" $2 "|" $3; next }
{ if (collect) print collect; prev = $1; collect = $1 "|" $2 "|" $3; next }
END { if (collect) print collect }'
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|