How to Separate Odd and Even number from one data set?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to Separate Odd and Even number from one data set?
# 1  
Old 05-18-2011
Bug How to Separate Odd and Even number from one data set?

Hi,
If I want to separate data set to new file by odd and even number.
If data set like this

1 ABC 235 hgf
2 DEF 326 kjk
3 XXX 133 kwd
4 YYY 188 fgh


If I want separate by colum3
I want result like

set 1

1 ABC 235 hgf
3 XXX 133 kwd

put to new file(odd number.txt)

set 2
2 DEF 326 kjk
4 YYY 188 fgh
put to new file ( even number.txt)


How I make script or comman ?

I use Linux Centos.

Thank you very much
# 2  
Old 05-18-2011
Code:
awk '{if ($3%2){print > "set_1"}else{print > "set_2"}}' file

# 3  
Old 05-18-2011
Code:
awk '{f=($3%2)?"odd.txt":"even.txt";print > f }' infile

# 4  
Old 05-19-2011
Quote:
Originally Posted by ctsgnb
Code:
awk '{f=($3%2)?"odd.txt":"even.txt";print > f }' infile

Quote:
Originally Posted by bartus11
Code:
awk '{if ($3%2){print > "set_1"}else{print > "set_2"}}' file

I guess, "$3" can be replaced by "NR" to make it to work fine.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Process only 4 digit odd number starting with zero

I am trying to process only IonCode_odd #'s (always 4 digits starting with zero), but the below isn't working as expected. Is there a better way? Thank you :). IonCode_0401_xxxx_xxxx_xxxx.bam IonCode_0401_xxxx_xxxx_xxxx.bam.bai IonCode_0401_xxxx_xxxx_xxxx.fastq... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Find to delete lines with pattern and even or odd number

In the below directory I am trying to delete all lines with a .bam extention that have the pattern IonCode_ followed by an even number. I am also trying to delete all lines with a .fastq extention that have the pattern IonCode_ followed by an odd number. I was going to use find but can see all... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

How to separate rows of data into another column?

I have data such as below where the value in second field is the same as that in the row after. 123456,22222,John,0,xyz 234567,22222,John1,1,cde 43212,3333,Jean,3,pip 84324,3333,Abel,2,cat I'd like to rearrange the output like below to put such records beside each other and separated with... (5 Replies)
Discussion started by: james2009
5 Replies

4. Shell Programming and Scripting

Odd Behaviour for Set and IFS variable

Ok, so I'm playing around with delimters and reading files. and I came across this behaviour that I thought was a bit odd, regarding how the set command takes values... If I run this: IFS=$'-' #Assigns the - as the default delimiter for bash set I-love-my-gf-a-lot #uses set to put a bunch of... (1 Reply)
Discussion started by: Lost in Cyberia
1 Replies

5. Shell Programming and Scripting

Help awk/sed: putting a space after numbers:to separate number and characters.

Hi Experts, How to sepearate the list digit with letters : with a space from where the letters begins, or other words from where the digits ended. file 52087mo(enbatl) 52049mo(enbatl) 52085mo(enbatl) 25051mo(enbatl) The output should be looks like: 52087 mo(enbatl) 52049... (10 Replies)
Discussion started by: rveri
10 Replies

6. Shell Programming and Scripting

Divide data into separate files

frnds: i want to divide data on the behalf of dotted line and redirectd into new files ) ------------------------- M-GET CONFIRMATION ( ------------------------- M-GET CONFIRMATION ( INVOKE IDENTIFIER final data shuld be into 3 files ...... (6 Replies)
Discussion started by: dodasajan
6 Replies

7. UNIX for Dummies Questions & Answers

How to separate a single column file into files of the same size (i.e. number of rows)?

I have a text file with 1,000,000 rows (It is a single column text file of numbers). I would like to separate the text file into 100 files of equal size (i.e. number of rows). The first file will contain the first 10,000 rows, the second row will contain the second 10,000 rows (rows 10,001-20,000)... (2 Replies)
Discussion started by: evelibertine
2 Replies

8. Shell Programming and Scripting

separate the file according to the number of fields

I have a file which is delimetered by ',' i need to filter out a file with respect to the number of fileds in each line. a,s,d,f,g,h,j,k,l 1,2,3,3,4,5,6,7,6 a,2,3 4,5,6,7 in this i neeed to filter out the lines with 8 column to another file and rest to another file. so ... (3 Replies)
Discussion started by: ratheeshjulk
3 Replies

9. Shell Programming and Scripting

count data separate by comma

hi experts, i have some problem with count data which separate by comma, below sample data : 01,011222823b6d,011222823f29,0028a5,002993,6212345678, 659111111111,6598204507,6281105008,6596197849,_,525016160836958,_, ffffffff,000000000000000000000000,_,_,_,fd,fd,ff,00,1,0028a5-002993,_,... (10 Replies)
Discussion started by: bucci
10 Replies
Login or Register to Ask a Question