sort file with email adress


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort file with email adress
# 1  
Old 11-21-2011
sort file with email adress

Hi All,

I have a file which is "|" pipe delimited. The file has 3 fields. the last field contains email ids which has different host names.

I want to sort the file based on host name, which is in 3rd filed and needs to create a file for each host.

For example, if out of 1000 records, 10 records have host name @yahoo.com, i need to create file yahoo with all these 10 records.

Till now i have written below commands, but it is not helping me.

Code:
awk -F"@" '{print $2}' ABC.txt | sort -u >> a.txt
 
cat a.txt | whil read abc 
do
grep ${abc} | ABC.txt >> abc.txt
done

Any help? it creates the file, but it is not taking all records for a domain.
# 2  
Old 11-21-2011
can you provide the sample input data

---------- Post updated at 12:56 PM ---------- Previous update was at 12:52 PM ----------

Code:
 
awk -F"[\|\@.]" '{printf("%s\n",$0) > $4}' ABC.txt

---------- Post updated at 01:06 PM ---------- Previous update was at 12:56 PM ----------

in your example

Code:
 
grep ${abc} | ABC.txt >> abc.txt
#why pipe symbol is there in between the pattern and filename ?

# 3  
Old 11-21-2011
Hi itkamaraj,
While running your code, it says
Code:
$> awk -F"[\|\@.]" '{printf("%s\n",$0) > $4}' ABC.txt
awk: 0602-576 A print or getline function must have a file name.
 The input line number is 32. The file is ABC.txt.
 The source line number is 1.

Can you please tell me where to provide file name?
# 4  
Old 11-21-2011
can you provide the sample input data of ABC.txt
# 5  
Old 11-21-2011
Here is the sample data...
Code:
ABC.txt
======
001|D'ondu|arx@uil.us.in
002|D'souza|dsouza@yahoo.com
003|Peter|peter@gmail.com
004|Sadhu|sadhu@uil.us.in
 
Now need to create 3 files.

Code:
uil.us.in
=========
001|D'ondu|arx@uil.us.in
004|Sadhu|sadhu@uil.us.in
yahoo.com
=========
002|D'souza|dsouza@yahoo.com
gmail.com
=========
003|Peter|peter@gmail.com


Last edited by pludi; 11-21-2011 at 05:15 AM..
# 6  
Old 11-21-2011
Code:
awk -F'|' 'split($3, a, "@") { printf("%s\n", $0) >> a[2] }' ABC.txt

# 7  
Old 11-21-2011
its working fine.. try with nawk

Code:
bash-3.00$ cat inputfile
001|D'ondu|arx@uil.us.in
002|D'souza|dsouza@yahoo.com
003|Peter|peter@gmail.com
004|Sadhu|sadhu@uil.us.in
bash-3.00$ cat uil
001|D'ondu|arx@uil.us.in
004|Sadhu|sadhu@uil.us.in
bash-3.00$ cat yahoo 
002|D'souza|dsouza@yahoo.com
bash-3.00$ cat gmail 
003|Peter|peter@gmail.com

Code:
$ nawk -F"[\|\@.]" '{printf("%s\n",$0) > $4}' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script to find repeated IP adress from trace file (.tr)

+ 8.00747 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 63 id 0 protocol 17 offset (bytes) 0 flags length: 540 10.1.3.3 > 10.1.2.4) ns3::UdpHeader (length: 520 49153 >... (11 Replies)
Discussion started by: Nipa
11 Replies

2. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

3. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

4. Shell Programming and Scripting

Trying to get an IP adress from a file

This is probably a real n00b question but i`m not able to figure it out. I have a folder of configuration files that contain IP-adresses. The line i`m interested in looks like this: IP_ADDRESS="123.123.123.1123" Some have muliple ip adresses, so the line will look like : ... (5 Replies)
Discussion started by: DaneV
5 Replies

5. Shell Programming and Scripting

To find the IP adress in the log file

Hi, I need to find out the repeated IP address from the apache log file from my box. I did try to come out with the script, but I could not grep out the repeated Ip Address from the error_logs and need to redirect to a file. Can you guys please help me out of this problem. Thanks in... (9 Replies)
Discussion started by: gsiva
9 Replies

6. HP-UX

Change IP Adress

I want change my IP address and hostname in my machine by use the console. Can any one tell me how can I execute that by command ? Thanks & Regards (1 Reply)
Discussion started by: magasem
1 Replies

7. AIX

Capture IP Adress

hello I need for a script to capture the ip address from the connected user. I have 5 logical partitions. With "who", i have the ip adress, but only for 2 servers. Do you know another command to know the ip address of connected clients ? thank you (14 Replies)
Discussion started by: pascalbout
14 Replies

8. Solaris

IP-Adress

Hello together how can I find a ipadress from a login into remote system console? Thanks a lot Urs (1 Reply)
Discussion started by: MuellerUrs
1 Replies

9. UNIX for Dummies Questions & Answers

MAC-Adress

Hello I need to show my MAC-Adress on a Unix System, is there someone that know how? (2 Replies)
Discussion started by: nkochr
2 Replies
Login or Register to Ask a Question