dividing a file into two


 
Thread Tools Search this Thread
Top Forums Programming dividing a file into two
# 1  
Old 10-20-2006
dividing a file into two

Hi ..
I have a file which contains a list of numbers like..
Code:
1923,1924,1925,1926,1927,1928,1929,1930,1931,1932,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,
2028,2029,2030,2031,2032,2115,2116,2117,2118,2119,2120,2121,2122,2123,2124,2125,2126,2127,2128,2129,2130,2131,2132,
2215,2216,2217,2218,2219,2220,2221,2222,2223,2224,2225,2226,2227,2228,2229,2230,2231,2232,2315,2316,2317,2318,2319,
2320,2321,2322,2323,2324,2325,2326,2327,2328,2329,2330,2331,2332,2412,2413,2414,2415,2416,2417,2418,2419,2420,2421,
2422,2423,2424,2425,2426,2427,2428,2429,2430,2431,2432,2512,2513,2514,2515,2516,2517,2518,2519,2520,2521,2522,2523,
2524,2525,2526,2527,2528,2529,2530,2531,2532,2612,2613,2614,2615,2616,2617,2618,2619,2620,2621,2622,2623,2624,2625,
2626,2627,2628,2629,2630,2631,2632,2712,2713,2714,2715,2716,2717,2718,2719,2720,2721,2722,2723,2724,2725,2726,2727,
2728,2729,2730,2731,2732,2733,2810,2811,2812,2813,2814,2815,2816,2817,2818,2819,2820,2821,2822,2823,2824,2825,2826,
2827,2828,2829,2830,2831,2832,2833,2910,2911,2912,2913,2914,2915,2916,2917,2918,2919,2920,2921,2922,2923,2924,2925,
2926,2927,2928,2929,2930,2931,2932,2933,3010,3011,3012,3013,3014,3015,3016,3017,3018,3019,3020,3021,3022,3023,3024,
3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,3110,3111,3112,3113,3114,3115,3116,3117,3118,3119,
3120,3121,3122,3123,3124,3125,3126,3127,3128,3129,3130,3131,3132,3133,3134,3135,3136,3137,3210,3211,3212,3213,3214,
3215,3216,3217,3218,3219,3220,3221,3222,3223,3224,3225,3226,3227,3228,3229,3230,3231,3232,3233,3234,3235,3236,3237,
3310,3311,3312,3313,3314,3315,3316,3317,3318,3319,3320,3321,3322,3323,3324,3325,3326,3327,3328,3329,3330,3331,3332,
3333,3334,3335,3336,3337,

I have to divide the numbers in such a way that, all the numbers less than and equal to xx31 must be outputted to a seperate file, and all the numbers greater than and equal to xx32 must be outputted to a seperate file.

That means I should have the following files as output:
Code:
1923,1924,1925,1926,1927,1928,1929,1930,1931,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,
2115,2116,2117,2118,2119,2120,2121,2122,2123,2124,2125,2126,2127,2128,2129,2130,2131,
2215,2216,2217,2218,2219,2220,2221,2222,2223,2224,2225,2226,2227,2228,2229,2230,2231,
2315,2316,2317,2318,2319,2320,2321,2322,2323,2324,2325,2326,2327,2328,2329,2330,2331,
2412,2413,2414,2415,2416,2417,2418,2419,2420,2421,2422,2423,2424,2425,2426,2427,2428,2429,2430,2431,
2512,2513,2514,2515,2516,2517,2518,2519,2520,2521,2522,2523,2524,2525,2526,2527,2528,2529,2530,2531,
2612,2613,2614,2615,2616,2617,2618,2619,2620,2621,2622,2623,2624,2625,2626,2627,2628,2629,2630,2631,
2712,2713,2714,2715,2716,2717,2718,2719,2720,2721,2722,2723,2724,2725,2726,2727,2728,2729,2730,2731,
2810,2811,2812,2813,2814,2815,2816,2817,2818,2819,2820,2821,2822,2823,2824,2825,2826,2827,2828,2829,2830,2831,
2910,2911,2912,2913,2914,2915,2916,2917,2918,2919,2920,2921,2922,2923,2924,2925,2926,2927,2928,2929,2930,2931,
3010,3011,3012,3013,3014,3015,3016,3017,3018,3019,3020,3021,3022,3023,3024,3025,3026,3027,3028,3029,3030,3031,
3110,3111,3112,3113,3114,3115,3116,3117,3118,3119,3120,3121,3122,3123,3124,3125,3126,3127,3128,3129,3130,3131,
3210,3211,3212,3213,3214,3215,3216,3217,3218,3219,3220,3221,3222,3223,3224,3225,3226,3227,3228,3229,3230,3231,
3310,3311,3312,3313,3314,3315,3316,3317,3318,3319,3320,3321,3322,3323,3324,3325,3326,3327,3328,3329,3330,3331,
3409,3410,3411,3412,3413,3414,3415,3416,3417,3418,3419,3420,3421,3422,3423,3424,3425,3426,3427,3428,3429,3430,3431,
3509,3510,3511,3512,3513,3514,3515,3516,3517,3518,3519,3520,3521,3522,3523,3524,3525,3526,3527,3528,3529,3530,3531,
3609,3610,3611,3612,3613,3614,3615,3616,3617,3618,3619,3620,3621,3622,3623,3624,3625,3626,3627,3628,3629,3630,3631,
3709,3710,3711,3712,3713,3714,3715,3716,3717,3718,3719,3720,3721,3722,3723,3724,3725,3726,3727,3728,3729,3730,3731,
3809,3810,3811,3812,3813,3814,3815,3816,3817,3818,3819,3820,3821,3822,3823,
3909,3910,3911,3912,3913,3914,3915,3916,3917,3918,3919,3920,3921,3922,3923,
4009,4010,4011,4012,4013,4014,4015,4016,4017,4018,4019,4020,4021,4022,4023,
4109,4110,4111,4112,4113,4114,4115,4116,4117,4118,4119,4120,4121,4122,4123,
4209,4210,4211,4212,4213,4214,4215,4216,4217,4218,4219,4220,4221,4222,4223,
4309,4310,4311,4312,4313,4314,4315,4316,4317,4318,4319,4320,4321,4322,4323

and
Code:
1932,2032,2132,2232,2332,2432,2532,2632,2732,2733,2832,2833,2932,2933,
3032,3033,3034,3035,3036,3037,3132,3133,3134,3135,3136,3137,
3232,3233,3234,3235,3236,3237,3332,3333,3334,3335,3336,3337,
3432,3433,3434,3435,3436,3437,3532,3533,3534,3535,3536,3537,
3632,3633,3634,3635,3636,3637,3732,3733,3734,3735

Can anyone help?

Thankx
Jazz

Last edited by jazz; 10-20-2006 at 06:05 AM..
# 2  
Old 10-20-2006
If that is all that you need consider awk:
Code:
awk -F"," '{
    for(i=1;i<=NF;i++){
        if(substr($i,3,2)>31 ) {print $i > "bigger_file.dat"}
        else { print $i > "smaller_file.dat"}
    }

}' inputfilename

# 3  
Old 10-20-2006
Thankx a lot!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dividing by zero

Does anyone know how to include as a script maybe an "echo" warning that explains that if a user uses the second number "zero" when dividing, that the result will BE "zero." I need, example: 5/0 (second number) = 0, in script form. current script: echo "Enter a number" read num1 echo... (4 Replies)
Discussion started by: jefferj54
4 Replies

2. Shell Programming and Scripting

Dividing one file into several files

Hello, I am using Awk in UBUNTU 12.04. I have a file as follows, the first column represents the name of populations, in my real file, I have 47 populations and 2172 lines in total with about 47000 fields. ABO_1 1 2 ABO_1 1 2 ABO_2 1 1 GPO_1 1 1 GPO_1 2 2 GPO_2 1 0 GPO_2 2 0 I want... (3 Replies)
Discussion started by: Homa
3 Replies

3. UNIX for Dummies Questions & Answers

Dividing up a text file by columns

Hi, I have a space de-limited text file with 1000 columns. I want to divide it up into 20 text files each with 50 columns, starting from the first column. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

4. Shell Programming and Scripting

Dividing two numbers in unix

Hi, I have written this code the division of two numbers and multiply it by hundred (to get the percent) echo "script running for the 1st time" cp value_directory_present.txt /home/mysql_cnbc/value_directory_past.txt rm -f test6.txt value_directory_present.txt else y1=`awk '{print $1}'... (5 Replies)
Discussion started by: arijitsaha
5 Replies

5. Shell Programming and Scripting

Issues when dividing

Hi, I do have a very simple task to divide 2 variables and display the result. I CANNOT use bc when i try var1=2 var2=4 var3=$(($var1 / $var2)) echo $var3 the output is always 0 What can I change to get a dotted decimal result such as 0.5 ? Thanks! (5 Replies)
Discussion started by: svetoslav_sj
5 Replies

6. Shell Programming and Scripting

Dividing file into columns

Hi, I have a file containing 28048 lines and I would like to split it into a a file with 3506 lines and 8 columns? In column 1, I would like to have the first 3506 lines, in columns 2 the second 3506 lines and so on. I've been looking around in the forum but I found very specific cases. Is... (1 Reply)
Discussion started by: f_o_555
1 Replies

7. Shell Programming and Scripting

Problem with dividing

Hi All, I have two variables like below.. ETIMEHR =03 #END TIME HOUR ETIMEMIN=02 #END TIME MIN Now I'm converting the min to hour by deviding it by 60 ETIMEMINCONV=`echo "scale=2; $ETIMEMIN/60" | bc` but when i print ETIMEMINCONV instead of getting... (6 Replies)
Discussion started by: smarty86
6 Replies

8. Shell Programming and Scripting

Dividing single file by lines?

Hi, I have a situation where I need to append specific lines to a series of files only when specific lines are found. I can do this using sed -f, however because of the byte limitation for a sedscr file, I create multiple sedscr files (of 180 lines each due to the length of the strings) and do... (1 Reply)
Discussion started by: anoc
1 Replies

9. UNIX for Dummies Questions & Answers

Dividing float values

Hi I know its a dumb question but can any one please explain me the difference of executing a shell script in the following 2 ways. . script.sh sh script.sh I have a problem if I execute the following code as sh script.sh DB_CNT_ALW=0.20 SCT_VAR=0.05 if ; then echo "== Difference... (3 Replies)
Discussion started by: shash
3 Replies

10. UNIX for Dummies Questions & Answers

dividing the screen >>>

Hi! Is there is any way to divide the screen when I use UNIX shells (I have RedHat 7.1)? I have to see the command promt and process some data from very long file at the same time (I work with PThreads). Some "pseudo-windows" in text mode, huh? =) Thanks in advance and don't be angry =) (4 Replies)
Discussion started by: ShockTeam
4 Replies
Login or Register to Ask a Question