Split fields from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split fields from a file
# 8  
Old 09-05-2014
This awk script should group emails based upon the data following @:

Code:
awk '
{
for (x=1; x<=NF; x++) {
        split($x,em,"@")
        all[em[2]] = all[em[2]] ? all[em[2]] FS $x : $x
        }
}
END{
for (i in all) {
    c++
    print "Group: "c FS all[i]
    }
}' inputfile

# 9  
Old 09-05-2014
@Don Cragun : As i mentioned in my requirement, i want asdf@blh.com in one group; and the remaining id's in other group.

@RudiC : Thanks for your input.

Regards,
# 10  
Old 09-05-2014
Let's be perfectly clear. From your first post:
Quote:
My requirement is to seperate the email id's into 2 groups..
emailid1@blh.com emaild2@blh.com emailid3@blh.com should come in one group and asdf@blah.com should come in another group, so that i can call email functionality twice. Currently, i am using below code to achive this:
So, no matter what may appear in any file somewhere, what you want is:
Code:
group1='emailid1@blh.com emaild2@blh.com emailid3@blh.com'
group2='asdf@blah.com'

or with your changes since then:
Code:
group2='asdf@blh.com'

We all mistakenly assumed that you were trying to read a list of email addresses from a file and split them into groups based on some criteria derived from the addresses themselves. And since you had three addresses ending with "@blh.com" and one address ending with "@blah.com", we all assumed that that was the criteria to be used to determine which group should contain an address.

It could have been that you wanted addresses starting with "a" in one list and addresses starting with "e" in the other list. It could have been that you wanted addresses with a digit before the "@" in one list and addresses with an alphabetic before the "@" in the other list. It could have been that you wanted the 3rd address in one list and the other addresses in the other list. It could have been some other pattern none of us saw.

But, since you just want two lists containing exactly those names, why did you give us the red herring talking about a file containing your list of names??? The file is irrelevant.
# 11  
Old 09-05-2014
@Don Cragun : My sincere apologies for the confusion about the requirement !
The reason i gave the file name containing email address is, that is the way the shell script is set up [by the clients] to read email addresses.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to add plus or minus to fields and split another field

In the tab-delimited input below I am trying to use awk to -10 from $2 and +10 to $3. Something like awk -F'\t' -v OFS='\t' -v s=10 '{split($4,a,":"); print $1,$2-s,$3+s,a,$5,$6} | awk {split(a,b,"-"); print $1,$2-s,$3+s,b-s,b+s,$5,$6}' input should do that. I also need to -10 from $4... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Split a free form text delimited by space to words with other fields

Hi, I need your help for below with shell scripting or perl I/P key, Sentence customer1, I am David customer2, I am Taylor O/P Key, Words Customer1,I Customer1,am Customer1,David Customer2,I Customer2,am Customer2,Taylor (4 Replies)
Discussion started by: monishathampi
4 Replies

3. Shell Programming and Scripting

awk split lines without knowing the number of fields a-priori

I want to use awk to split fields and put them into a file but I don't know the number of fields for example, in the following line Ports: 22/filtered/tcp//ssh///, 53/open/tcp//tcpwrapped///, 111/filtered/tcp//rpcbind///, 543/filtered/tcp//klogin///, 544/filtered/tcp//kshell///,... (3 Replies)
Discussion started by: esolvepolito
3 Replies

4. Shell Programming and Scripting

awk to split one field and print the last two fields within the split part.

Hello; I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies

5. Shell Programming and Scripting

AWK:Split fields separated by semicolon

Hi all, I have a .vcf file which contains 8 coulmns and the data under each column as shown below, CHROM POS ID REF ALT QUAL FILTER INFO 1 3000012 . A G 126 ... (6 Replies)
Discussion started by: mehar
6 Replies

6. Shell Programming and Scripting

how to split the row(array) in to fields and store in to oracle database in unix

Hi, the csv file with the delimeter #. A#B#C#D#E#F#G#H 1#2#3#4#5#6#7#8 Z#x#c#V 7#2#8#9 N. I want to read the file line by line and store in rowarray. then the rowarray content should be spilt or made to fields using the delimeter #. i am not sure can we store the fields in to... (3 Replies)
Discussion started by: barani75
3 Replies

7. Web Development

split the fields in a column into 3 columns

Have a column "address" which is combination of city, region and postal code like. Format is : city<comma><space>region<space>postal code abc, xyz 123456 All these three city, region and postal code are not mandatory. There can be any one of the above. In that case a nell... (2 Replies)
Discussion started by: rakshit
2 Replies

8. Shell Programming and Scripting

How to split a field into two fields?

Hi, I have a comma delimited text file where character fields (as opposed to numeric and date fields) are always enclosed with double quotes. Records are separated by the newline character. In a shell script I would like to split a particular field into two separate fields (enclosed with double... (4 Replies)
Discussion started by: vbrown
4 Replies

9. Shell Programming and Scripting

split varibles and store fields into shell varible array

I need to split a long varible which is a whole line read from a file into fields and store them in an array, the fields are delimited by pipe and a field may contain white spaces. I tried the following concept test and it has problem with field 5 which contain a space, appearently so because... (3 Replies)
Discussion started by: gratus
3 Replies

10. Shell Programming and Scripting

returning split fields

I have a variable with data in this format field1;field2;field3 I wanted to split the variable like this field1 field2 field3 this statement was working fine echo $key_val | awk '{gsub(";" , "\n"))' but sometimes we get the data in the variable in this format... (3 Replies)
Discussion started by: mervin2006
3 Replies
Login or Register to Ask a Question