how to arrange 3 file to one using awk...?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to arrange 3 file to one using awk...?
# 8  
Old 01-09-2008
MySQL

Quote:
Originally Posted by ghostdog74
not that it matters unless there's a performance issue for large files, you can do away with the cat. use file indirection to the while loop instead. cuts down one process Smilie
Good point! UUoC I believe Smilie
Well spotted!
# 9  
Old 01-17-2008
hello, I got stuck again,
how to make this table convert horizontally :

userA var1 1000
userA var1 1200
userA var2 2000
userA var2 1000
userB var2 3000
userB var3 4000
userB var3 2000
userB var4 5000
userC var1 6000

become like this table :
userA 2200 3000 0 0
userB 0 3000 6000 5000
userC 6000 0 0 0

with this format :
user (sum col3 where col2=var1 && col1=user) (sum col3 where col2=var2 && col1=user) (sum col3 where col2=var3 && col1=user) (sum col3 where col2=var4 && col1=user)

very very thanks again for your helps.....
Smilie

regards,
# 10  
Old 01-17-2008
please correct my script with more efficient sript :

Code:
awk '
NR==FNR{user[$1]=$1;userv[$1"1"]=0;userv[$1"2"]=0;userv[$1"3"]=0;userv[$1"4"]=0}
NR!=FNR{
if($2=="var1")
        userv[$1"1"]+=$3
else if($2=="var2")
        userv[$1"2"]+=$3
else if($2=="var3")
        userv[$1"3"]+=$3
else if($2=="var4")
        userv[$1"4"]+=$3
}
END{
for(i in user)
        print user[i]" "userv[i"1"]" "userv[i"2"]" "userv[i"3"]" "userv[i"4"]
}
' file file

thank you...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Arrange file by modified date

Hi, Am performing a find based on filename and result can contain multiple files being found Let's say my find command is find /Archive -f -name 12345.pdf and result of find command is /Archive/Folder A/12345.pdf /Archive/Folder B/12345.pdf please note white space in folder names I... (2 Replies)
Discussion started by: gigagigosu
2 Replies

2. Shell Programming and Scripting

Shell scripting - need to arrange the columns from multiple file into a single file

Hi friends please help me on below, i have 5 files like below file1 is x 10 y 20 z 15 file2 is x 100 z 245 file3 is y 78 z 23 file4 is x 100 (3 Replies)
Discussion started by: siva kumar
3 Replies

3. Shell Programming and Scripting

script to arrange file in specific format

Hi All, I am new to forum, I am looking to arrange a file in specific format but unable to get the formula to do it, already googled for the same, but didnt find the answer :(. hope to get help here :o:o:o:o:o I have to files : $ cat Dev_List2 0685 0686 0687 0688 0689 068A 068B 068C... (2 Replies)
Discussion started by: prasan_Aix
2 Replies

4. Shell Programming and Scripting

awk to search similar strings and arrange in a specified pattern

Hi, I'm running a DB query which returns names of people and writes it in a text file as shown below: Carey, Jim; Cena, John Cena, John Sen, Tim; Burt, Terrence Lock, Jessey; Carey, Jim Norris, Chuck; Lee, Bruce Rock, Dwayne; Lee, Bruce I want to use awk and get all the names... (9 Replies)
Discussion started by: prashu_g
9 Replies

5. Shell Programming and Scripting

Arrange / format data using awk

Input 217:fngadi4osa:fngadi4osa:M 217:415744:N/A 227:fngadi4osa:fngadi4osa: M 227:51200:N/A 228:fngadi4osa:fngadi4osa: M 228:102400:N/A 65:sapgt04:sapgt04: M 65:104448:N/A 228:fngadi4osa:fngadi4oma: M 228:102400:N/A Output 217:fngadi4osa:fngadi4osa:M 217:415744:N/A... (3 Replies)
Discussion started by: greycells
3 Replies

6. Shell Programming and Scripting

Re-arrange column

10.142.7.155 - - www.abc.com 404 - I have many columns which is tab delimited file, I have to re-arrange this to a particular column and also add "-" to 3rd column and 6th column. 10.142.7.155 - - - www.abc.com - 404 - (4 Replies)
Discussion started by: sandy1028
4 Replies

7. Shell Programming and Scripting

Arrange log files with AWK

Hello friends, I have too many log files to arrange. I use a simple script to create log files with below format and i forgot to create daily directory for them at the beginning. Because of this i should move all daily logs into a directory that i need to create. a part of "ls -l" output:... (1 Reply)
Discussion started by: EAGL€
1 Replies

8. Shell Programming and Scripting

how to arrange all lines in a file to a single line

Hi Gurus, I am a starter with shell script. Help me to achieve this. I have a file with lines given below. line1 line2 line3 . . etc How can I arrange the file which should look like line1,line2,line3,..,..,etc Any help on this is appreciated. (9 Replies)
Discussion started by: smv
9 Replies

9. Shell Programming and Scripting

re arrange data

Any idea in awk or sed? $cat file a b c 2 4 5 6 output: a b c 2 4 5 6 (3 Replies)
Discussion started by: kenshinhimura
3 Replies

10. UNIX for Dummies Questions & Answers

Reverse Arrange File

I've got hundreds of lines in a file that looks like this: Line1 CCR CCH Line2 ICVM FBO GSC Line3 MKF The result should be like the one below so that I can insert them on our database. Line1 CCR Line1 CCH Line2 ICVM Line2 FBO Line2 GSC Line3 MKF Thanks in advance! (4 Replies)
Discussion started by: The One
4 Replies
Login or Register to Ask a Question