Fill the Key fields : Please help us


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fill the Key fields : Please help us
# 8  
Old 04-03-2008
Help needed ...

awk 'NF!=10{for(i=1;i<=(10-NF);i++)printf("%s,",k[i]);print;next}{for(i=1;i<=3;i++)k[i]=$i}1' FS=',' f1

This code is working for some what .

it is not working in case of ',' or '|' seperated



E100|0|5/29/1993|0|E001|E000|A|500000|41666.667|240.384615
|0|1/23/1994|0|E001|E003|A|125400|10450|60.288462
| |0|6/4/1994|0|E001|E003|A|95000|7916.667|45.673077
E101|0|7/30/1993|0|E001|E003|A|87000|7250|41.826923
| |1/9/1993|0|E001|E003|A|45200|3766.667|21.730769
E103|0|2/3/1995|0|E001|E003|A|15000|1250|7.211538
E104|0|2/15/1995|0|E001|E001|A|78000|6500|37.5


can u help me ..........
# 9  
Old 04-03-2008
Hi, u need to improve your research efforts, ..:
Code:
>cat file
E100|0|5/29/1993|0|E001|E000|A|500000|41666.667|240.384615
|0|1/23/1994|0|E001|E003|A|125400|10450|60.288462
| |6/4/1994|0|E001|E003|A|95000|7916.667|45.673077
E101|0|7/30/1993|0|E001|E003|A|87000|7250|41.826923
| |1/9/1993|0|E001|E003|A|45200|3766.667|21.730769
E103|0|2/3/1995|0|E001|E003|A|15000|1250|7.211538
E104|0|2/15/1995|0|E001|E001|A|78000|6500|37.5

Code:
>awk '{gsub(/^\|| +\|/,"")                                                                                                         
 if(NF!=10){for(i=1;i<=(10-NF);i++)printf("%s|",k[i]);print;next}
{for(i=1;i<=3;i++)k[i]=$i}print}' FS='|' file
E100|0|5/29/1993|0|E001|E000|A|500000|41666.667|240.384615
E100|0|1/23/1994|0|E001|E003|A|125400|10450|60.288462
E100|0|6/4/1994|0|E001|E003|A|95000|7916.667|45.673077
E101|0|7/30/1993|0|E001|E003|A|87000|7250|41.826923
E101|0|1/9/1993|0|E001|E003|A|45200|3766.667|21.730769
E103|0|2/3/1995|0|E001|E003|A|15000|1250|7.211538
E104|0|2/15/1995|0|E001|E001|A|78000|6500|37.5

# 10  
Old 04-07-2008
hi

awk '{gsub(/^\|| +\|/,"") if(NF!=10){for(i=1;i<=(10-NF);i++)printf("%s|",k[i]);print;next} {for(i=1;i<=3;i++)k[i]=$i}print}' FS='|' key.txt


when i am using this entire comand in a single line it is throw ing syntax error........but when i am using the above code in a two line it is working fine..............

i wann to store this entire into a script and i wann to call this dynamiclly...

thanks charan
# 11  
Old 04-08-2008
very urgent

hi friend,
file1.
12345|DZ012|20071220|FG456|234567|IND
| |20080101|DE345|456789|USA
|DZ012| | |500001|AUS
45678|ED456|20011203|ED345|456789|CAN
|SD345| | |456790|MEX
| | |DF232|567890|ARG
56789|WQ456|20071230|WD456|789012|WES
56789|AQ234|20080120|WS456|890123|JAM

when we are running the script we are getting error
awk '{gsub(/^\|| +\|/,"")
if(NF!=6){for(i=1;i<=(6-NF);i++)printf("%s|",k[i]);print;next} {for(i=1;i<=4;i++)k[i]=$i}print}' FS='|' key

out put
12345|DZ012|20071220|FG456|234567|IND
12345|DZ012|20080101|DE345|456789|USA
12345|DZ012|20071220|DZ012|500001|AUS
45678|ED456|20011203|ED345|456789|CAN
45678|ED456|20011203|SD345|456790|MEX
45678|ED456|20011203|DF232|567890|ARG
56789|WQ456|20071230|WD456|789012|WES
56789|AQ234|20080120|WS456|890123|JAM



45678|ED456|20011203|SD345|456790|MEX here the 2n column is repated and the 2nd column moved to 4column.......and the 4th column is missing....some more buggs are there


the above key vlaues should populate as it is...........very urgent
# 12  
Old 04-08-2008
Code:
 vnix$ awk -F'|' 'BEGIN { OFS="|"; }
> { for(i=1;i<=NF;++i) { if ($i=="" || $i==" ") $i=k[i]; k[i]=$i; } print; }' <<HERE
> 12345|DZ012|20071220|FG456|234567|IND
> | |20080101|DE345|456789|USA
> |DZ012| | |500001|AUS
> 45678|ED456|20011203|ED345|456789|CAN
> |SD345| | |456790|MEX
> | | |DF232|567890|ARG
> 56789|WQ456|20071230|WD456|789012|WES
> 56789|AQ234|20080120|WS456|890123|JAM
> HERE
12345|DZ012|20071220|FG456|234567|IND
12345|DZ012|20080101|DE345|456789|USA
12345|DZ012|20080101|DE345|500001|AUS
45678|ED456|20011203|ED345|456789|CAN
45678|SD345|20011203|ED345|456790|MEX
45678|SD345|20011203|DF232|567890|ARG
56789|WQ456|20071230|WD456|789012|WES
56789|AQ234|20080120|WS456|890123|JAM

This is pretty much the code I posted a week ago, adapted for the changed field separator and the changed convention for a skipped field (missing vs. empty).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join and merge multiple files with duplicate key and fill void columns

Join and merge multiple files with duplicate key and fill void columns Hi guys, I have many files that I want to merge: file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: (5 Replies)
Discussion started by: yjacknewton
5 Replies

2. UNIX for Dummies Questions & Answers

Fill fields with awk from an array?

Hi experts, I have been trying for a while to accomplish the following task using awk, and I just don't seem find find a way. I am not particular about using awk, it just seemed like the logical choice at first. I have a file that contains 5 fields that are delimited by a space character.... (1 Reply)
Discussion started by: GermanicGalore
1 Replies

3. Solaris

Solaris 8 ssh public key authentication issue - Server refused our key

Hi, I've used the following way to set ssh public key authentication and it is working fine on Solaris 10, RedHat Linux and SuSE Linux servers without any problem. But I got error 'Server refused our key' on Solaris 8 system. Solaris 8 uses SSH2 too. Why? Please help. Thanks. ... (1 Reply)
Discussion started by: aixlover
1 Replies

4. Shell Programming and Scripting

Compare Fields from two text files using key columns

Hi All, I have two files to compare. Each has 10 columns with first 4 columns being key index together. The rest of the columns have monetary values. Using Perl, I want to read one file into hash; check for the key value availability in file 2; then compare the values in the rest of 6... (2 Replies)
Discussion started by: Sangtha
2 Replies

5. Shell Programming and Scripting

Perl function to sort a file based on key fields

Hi, I am new to PERL.I want to sort all the lines in a file based on 1,2 and 4th filelds. Can U suggest me a command/function in perl for this operation.. (5 Replies)
Discussion started by: karthikd214
5 Replies

6. Shell Programming and Scripting

Matching by key fields

I have a file (key.dat) that contains two columns: AA|1234| BB|567| CC|8910| I have another file (extract.dat) that contains some data: SD|458|John|Smith| AA|3345|Frank|Williams| AA|1234|Bill|Garner| BD|0098|Yu|Lin| BB|567|Gail|Hansen| CC|8910|Ken|Nielsen| I want to compare the... (5 Replies)
Discussion started by: ChicagoBlues
5 Replies

7. UNIX for Dummies Questions & Answers

Pressing backspace key simulates enter key

Hi, Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused: Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies

8. Shell Programming and Scripting

align several fields and fill spaces with zero

hi all, i have a big problem, and i don“t know what to do. i have a flat file with several fields, which are separated by ";" like this: 5656838-7B;97030000-7;*;V16106133 ;1;1; 4612062-0B;97030000-7;*;C14038149 ;1;2; 8044938-0B;97030000-7;*;V16034219 ;1;2; where B is a blank space. ... (2 Replies)
Discussion started by: DebianJ
2 Replies

9. Solaris

Esc key/Auto-fill

I'm an HPUX/Linux guy, who appreciates occasionally hitting the Esc key for Auto-fill... Does sunOS have anything like this? This is my 1st post, and I didn't want to waste it :D thanks, manuel (3 Replies)
Discussion started by: mr_manny
3 Replies
Login or Register to Ask a Question