adjust files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users adjust files
# 1  
Old 12-19-2005
adjust files

hi...
i have a big problem, and i don't know how to solve it.
here is the thing: i have 12 files, which are flat files, with several records(lines), and each record has 3 fields, wich are separated by pipe (|), something like this:

file 1:
33|12|2000
33|22|3000
66|24|3000
99|48|4000
104|50|5000

...

file n :
33|20|1000
104|20|2000
300|20|2000

the first field is a code, wich i can access it in another file. the thing is: i would like join them in one file, order by code. Something like this:

33|12|2000|20|1000
33|22|3000
66|24|3000
99|48|4000
104|50|5000|20|2000
300|20|2000

is that possible?
any idea, thanks
# 2  
Old 12-19-2005
[not tested]
nawk -F'|' -v OFS='|' -f deb.awk files*

deb.awk:
Code:
{  arr[$1] = (($1 in arr) ? arr[$1] OFS : "") $2 OFS $3 }
END {
   for (i in arr)
      print i, arr[i]
}

# 3  
Old 12-19-2005
question

thanks vgersh99, but if is not problem, i would like make you a question:

how can i do it to order the new file by the first 2 fields, when the 2 first fields have the same value, like this:

file 1:
1|11|1111
1|22|2222
3|33|3333
3|44|4444
3|55|5555

...

file n :
1|11|1000
1|22|2000
1|77|2000
3|55|3000

exit file:
1|11|1111|1000
1|22|2222|2000
1|77|2000
3|33|3333
3|44|4444
3|55|5555|3000


thanks for your help.....
# 4  
Old 12-19-2005
nawk -F'|' -v OFS='|' -f deb.awk files*

deb.awk:
Code:
{  idx = $1 OFS $2; arr[idx] = ((idx in arr) ? arr[idx] OFS : "") $3 }
END {
   for (i in arr)
      print i, arr[i]
}

# 5  
Old 12-19-2005
thanks

thanks a lot vgersh99

anyway, i still have a little question, if you can answer me i will thank a lot...
how can i do to keep white spaces, delimited by pipe (|), when there are not values in one of the 12 files, for one record(line). example:

file 1:
1|11|1111
1|44|4444
1|99|9999
3|55|5555

file 2:
1|99|8888
3|55|9000
...

file n :
1|11|1000
1|22|2000
1|33|3000
3|55|4000

exit file:
1|11|1111| |1000
1|22| | |2000
1|33| | |3000
1|44|4444|
1|99|9999|8888|
3|55|5555|9000|4000

thanks a lot...
# 6  
Old 12-19-2005
let me get straight!
so your 'unique key' is the FIRST and the SECOND field. And the rest of the line contains as many fields as there are files: the files that have 'unique fields' have values in the corresponding field AND the files that don't - will have empty field.

So if you had 5 files, you would have 7 fields in the resulting file:
2 fields with the unique keys
5 fields with values/empty for every 5 of the input files

Is that somewhat close to what you're looking for?
# 7  
Old 12-19-2005
answer

yes vgersh99, that is what i'm looking for.

if i had 5 files, i would have 7 fields in the resulting file:
2 fields with the unique keys
5 fields with values/empty for every 5 of the input files

and each field separated by pipe (|)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to seperate text and adjust format like this?

in example.txt file is below ADD PDU:SRN=0,PDUID=LOCAL,NAME="PDU_0",PSV=LOW,MOG="PUBLIC",REFERABLE=YES; ADD PDU:SRN=2,PDUID=LOCAL,NAME="PDU_1",PSV=LOW,MOG="PUBLIC",REFERABLE=YES; ADD MODULE:MID=84,MT=DSU,SRN1=0,SN1=4,MNAME="DSU84"; ADD MODULE:MID=85,MT=DSU,SRN1=0,SN1=4,MNAME="DSU85"; How to... (2 Replies)
Discussion started by: swensens
2 Replies

2. Solaris

can't adjust time : not owner

Hi experts, I m new to solaris. I am getting following errror in /var/adm/messages file on one of the solaris 10 zones - xntpd: Can't set time of day: Not owner xntpd daemon is online. Any help on this ? (3 Replies)
Discussion started by: sunadmin
3 Replies

3. Shell Programming and Scripting

Script to adjust system time

Hello everyone, I am trying to write a script that will accomplish the following: - query current system time and store result into a variable - wait for some amount of time, say 300 seconds - reset system time to earlier queried time + 1 second I did some basic shell scripting (CSH... (11 Replies)
Discussion started by: xaiu
11 Replies

4. Shell Programming and Scripting

Script to adjust network settings

Hello, Newbie question on scripting - I'm looking to create a simple script that will work on RHEL5 that will adjust the network settings: ip address, default gateway, and subnet mask. If anything else needs to be done (service network stop / start) or should be done to make settings active - I... (4 Replies)
Discussion started by: rojizo
4 Replies

5. OS X (Apple)

Adjust X & Y screen axis

I'm using my wife's Macbook, and I just noticed that her screen is off axis, but I can't find a way to adjust it. I've tried playing around with resolution in preferences, but nothing. Maybe a terminal command for adjusting the x and y values of the screen? Any and all suggestions welcomed :) (2 Replies)
Discussion started by: andou
2 Replies

6. Shell Programming and Scripting

How to adjust spacing

Is there a way to adjust spacing of a line using k shell? e.g I have a file below $ cat file1 AAA BBB CCC A B C AAAA BB CC I want each word to be adjusted with spaces to have 10 character length like below: AAA BBB CCC A B C AAAA BB CC Any... (4 Replies)
Discussion started by: stevefox
4 Replies

7. UNIX for Advanced & Expert Users

Adjust format file

Hi all... i have a question, and i don`t know what to do ... i have a flat file what is separated by ";" and i need format it... here is an example: this is what i have: AAA ; BBB ; 1 ; 1.1 ; 1.2 ; 1.3 ; 2 ; 2.1 ; 2.2 ; 2.3 ; 3 ; 3.1 ; 3.2 ; 3.3 ; ....... ......... there are a lot of... (4 Replies)
Discussion started by: DebianJ
4 Replies

8. Shell Programming and Scripting

Adjust the db script

Enclosing a script that is used everyday for database shutdown. In here you will find some code that checks oracle version. That part is very unnecessary since we use only 8.1.7 and will never go back.. Can anyone help me by modifying the code, to never use that part and readjust so script does... (1 Reply)
Discussion started by: ST2000
1 Replies

9. Filesystems, Disks and Memory

Cannot adjust division

I have a doubt with an error message, and i want to be sure if this is a normal situation or not. Situation: I was formating and installing a SCSI 36Gb HD with UNIX SCO 5.05, the problem happens when is making the division and filesystem on disk 1, and the message error is "Exit value 139... (1 Reply)
Discussion started by: jav_v
1 Replies
Login or Register to Ask a Question