Uregnet help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Uregnet help
# 1  
Old 03-10-2008
Uregnet help

Hi friends,

My ETL is generating fixed width file. I want to remove 1st column value from the file and put it as a file name and created multiple file,

here is my file

100 abcd ert100 fhgty300rytu
100 cvbd fgh500 rtyuh400rtnb
200 dbcd ert100 fhgty300rytu
200 vvbd fgh500 rtyuh400rtnb
300 dbcd ert100 fhgty300rytu
300 wvbd fgh400 rtyuh400rtnb

I want to create following files

100.txt
abcd ert100 fhgty300rytu
cvbd fgh500 rtyuh400rtnb

200.txt
dbcd ert100 fhgty300rytu
vvbd fgh500 rtyuh400rtnb


300.txt
dbcd ert100 fhgty300rytu
wvbd fgh400 rtyuh400rtnb

i really appreciate ur input.

thanks
sunny
# 2  
Old 03-10-2008
Code:
awk '!x[$1]++{close(fn);fn=$1".txt"}{sub(/[^ ]* /,"");print>fn}' file

Use nawk or /usr/xpg4/bin/awk on Solaris.
# 3  
Old 03-10-2008
Didn't we just answer this question last week?
input:
Quote:
/home/jmcnama> cat filename
100 record1 more junk to test this line
100 record2
200 record3
200 record4
Code:
awk '{ file=sprintf("%s.txt", $1);
       for(i=2; i<=NF; i++) 
           {fmt=(i==NF)?"%s\n" :"%s "
            printf(fmt,$i) > file
           } 
     }' inputfilename

output:
Quote:
/home/jmcnama> cat 100.txt
record1 more junk to test this line
record2
/home/jmcnama> cat 200.txt
record3
record4
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question