[ask]filtering file to indexing...

dear all,

i have file with format like this
file_master.txt

20110212|231213|rio|apri|23112|222222
20110212|312311|jaka|dino|31223|543234
20110301|343322|alfan|budi|32131|333311
...

i want filter with output like this
index_nm.txt

rio|apri
jaka|dino
...

index_years.txt

20110212
20110212
20110301
...

any idea for this??

cut -d'|' -f1 input_file > index_years.txt
cut -d'|' -f3,4 input_file > index_nm.txt
1 Like

thx @SL for replaying

i have solve in my case with awk like this

:smiley:

@shell_life
its simple code :b: nice to use thx for your advice

r.a.r

awk -F'|' '{print $1  > "file.one"; print $3 "|" $4 > "file.two"}'
1 Like

@all
how about if input like this

20110212|231213|rio|apri|23112|222222
20110214|312311|jaka|dino|31223|543234
20110303|343322|alfan|budi|32131|333311
20110304|342343|tari|niki|32131|333311

and output
file201102.txt

20110212|231213|rio|apri|23112|222222
20110212|312311|jaka|dino|31223|543234 

file201103.txt

20110303|343322|alfan|budi|32131|333311
20110304|342343|tari|niki|321323|3323422 

so i can create cluster file201102.txt willbe sorting all date 201102*
and file201103.txt willbe sorting all date 201103*

thx for your advice
r.a.r

awk '{print $0 > "file."  substr($1, 5, 2)}'

Better:

awk '{print > "file"  substr($0,1,6) ".txt"}'

Apply substr on $1 and need to tweek a bit as below:

awk -F "|" '{ print > substr($1,1,6) }' OFS="|" input_file