Print separated datas


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print separated datas
# 1  
Old 05-30-2010
Print separated datas

Hi People !!

I need your help.

I have a a txt file "example" with it datas.

Code:
[Hour]  [Data]   [IP]   [URL]  [ASN]  [Country] [Domain ASN Responsable]

11:35 10/12/2003  10.10.10.1    God.com  5  country   Responsable of ASN
11:37 12/12/2003  10.10.10.1    FATHER.COM  5  country   Responsable of ASN
11:40 14/12/2003  10.10.10.3    www.mother  6  country   Responsable of ASN
11:45 14/12/2003  10.10.10.3    www.daugher  6  country   Responsable of ASN
12:50 18/12/2003  100.100.10.1  son.com  8  country   Responsable of ASN
12:55 18/12/2003  100.100.10.1   Cousin Corporation of America  8  country   Responsable of ASN

I want to print just ASN that are about my responsibility, this example only that with ASN , 5 and 6.

Example: I am using this command
Code:
egrep '5|6' example

This is a output of my command.
Code:
11:35 10/12/2003  10.10.10.1    God.com  5  country   Responsable of ASN
11:37 12/12/2003  10.10.10.1    FATHER.COM  5  country   Responsable of ASN
11:40 14/12/2003  10.10.10.3    www.mother  6  country   Responsable of ASN
11:45 14/12/2003  10.10.10.3    www.daugher  6  country   Responsable of ASN

But I wanted that my output wil be this:
Code:
ASN5=11:35 10/12/2003  10.10.10.1  God.com  5  country  Responsable of ASN
 11:37 12/12/2003  10.10.10.1    FATHER.COM  5  country   Responsable of ASN

ASN6=11:40 14/12/2003  10.10.10.3    www.mother  6  country  Responsable of ASN
 11:45 14/12/2003  10.10.10.3    www.daugher  6  country   Responsable of ASN

Because after i wil need to send e-mail to ASN5 and ASN6 separated.

Thanks all

Last edited by Scott; 06-01-2010 at 07:02 PM.. Reason: Please use code tags
# 2  
Old 05-30-2010
Hi,

Using grep as you do will not work as it will capture 5 and 6 anywhere in the line. If you have a date or time that has a 5 or 6 in it, grep will return the line.

Have a go with this awk snippet:

Code:
awk '$5==5||$5==6{a[$5]=a[$5] (a[$5]?"\n":"") $0}END{for(i in a) print "ASN"i"=",a[i]"\n"}' input.file

# 3  
Old 05-31-2010
Quote:
Originally Posted by ras
Because after i will need to send e-mail to ASN5 and ASN6 separated.
What about
Code:
awk '$(NF-4)~/^[5\|6]$/{print > ("ASN"$(NF-4)".result")}' in.file

# 4  
Old 05-31-2010
Quote:
Originally Posted by danmero
What about
Code:
awk '$(NF-4)~/^[5\|6]$/{print > ("ASN"$(NF-4)".result")}' in.file

Or simply [56] for the regex pattern Smilie
# 5  
Old 05-31-2010
Almost there

Hi good person.I hope that help me

Then When I try to do with these commands . I m with problem.

My file is so.

Code:
# Global Variables
DIR="/myhome"
WHOIS="whois.pl"
TEMPLATE="$DIR/mytemplate"
EMAIL="$DIR/email.$$"
TO="myemail"


I wanted to put result of command in variable with the example:

Code:
ASNS=`awk '$5==5||$5==6{a[$5]=a[$5] (a[$5]?"\n":"") $0}END input.file `

Because I will need other data in ASNS.
I want to do "Whois" in the field IP inside the ASNS variable

I wanted that for each line of my variable ASNS . The variable IP catch the value of field IP that is inside the $ASNS and to execute command whois, after this his send e-mail to me and starting again with second data of variable ASNS.And finally replacing field <IP> and field <data> set in my template.

I tried so , but isn't work. My for is wrong.

Code:
for I in `echo $ASNS`; do               
       IP= $ASNS | awk ' { print $3 } '  "is it field of my ip in my input.file"
       for j in  `echo $IP`; do
            # Information of WHOIS
             echo " **** WHOIS **** " > $EMAIL
             $WHOIS $I >> $EMAIL
            echo " *************** " >> $EMAIL
            echo "  " >> $EMAIL

           # Conteudo do email
            cat $TEMPLATE >> $EMAIL
            sed -i s/"<IP>"/$I/ $EMAIL
            DATA=`echo $ASNS | sed 's/ / /g'`
             sed -i s#"<data>"#"$DATA"# $EMAIL
           done
done

Thanks all

Last edited by Scott; 06-01-2010 at 07:03 PM.. Reason: Code tags, please...
# 6  
Old 06-01-2010
  • Please use [code] tags when you post data or code sample.
  • Please remove useless UUOC
  • State your environment/shell

Base on your second post you need something like:
Code:
# eval "$(awk '$5==5||$5==6{a[$5]=((a[$5])?a[$5]"\n":"ASN"$5"=\"")$0}END{for(i in a)print a[i]"\""}' file)"
# echo "$ASN6"
11:40 14/12/2003 10.10.10.3 www.mother 6 country Responsable of ASN
11:45 14/12/2003 10.10.10.3 www.daugher 6 country Responsable of ASN
# echo "$ASN5"
11:35 10/12/2003 10.10.10.1 God.com 5 country Responsable of ASN
11:37 12/12/2003 10.10.10.1 www.father.com 5 country Responsable of ASN

Wait a second , you need only the IP, lets try
Code:
# eval "$(awk '$5==5||$5==6{a[$5]=((a[$5])?a[$5]"\n":"ASN"$5"=\"")$3}END{for(i in a)print a[i]"\""}' file)"
# echo "$ASN5"
10.10.10.1
10.10.10.1
# echo "$ASN6"
10.10.10.3
10.10.10.3

and
Code:
# while read IP;do echo $IP;done <<< "$ASN5"
10.10.10.1
10.10.10.1

I hope you can fix your script from here.
Success,
# 7  
Old 06-01-2010
Almost There

Hi danmero.

I think that I didn't explained correctly my question.
My english is poor then I think it's a problem.
If you can help me ,, it will be good.

I need to print all ASN that are about my responsability.

In this case ASN5 and ASN6 together so.


I m put this in variable , Im using it.

Code:
#FirstVariable=`egrep '5|6|' myfile  | awk '{print $3}' | sort | uniq `

11:35 10/12/2003 10.10.10.1 God.com 5 country Responsable of ASN
11:37 12/12/2003 10.10.10.1 FATHER.COM 5 country Responsable of ASN
11:40 14/12/2003 10.10.10.3 www.mother 6 country Responsable of ASN
11:45 14/12/2003 10.10.10.3 www.daugher 6 country Responsable of ASN

Now I need to get field "IP" inside the variable First .
Because I need to do "WHOIS" in each "IP"
Code:
#SecondVariable=10.10.10.1 and 10.10.10.10.3

After this I need to do command " WHOIS" , i have a script to do "WHOIS".
Then I think that could be make so.

Code:
#for I in `echo $IP`; do 
#	echo "  WHOIS  " > $EMAIL
#	$WHOIS $I >> $EMAIL
#	echo " -- " >> $EMAIL
#	echo "  " >> $EMAIL

When I do this "command for" i want to print my line(s) that are related with my ip , so.

First Time print this
Code:
#11:35 10/12/2003 10.10.10.1 God.com 5 country Responsable of ASN
#11:37 12/12/2003 10.10.10.1 FATHER.COM 5 country Responsable of ASN

And send e-mail .
I did it.

Second Time print this
Code:
11:40 14/12/2003 10.10.10.3 www.mother 6 country Responsable of ASN
11:45 14/12/2003 10.10.10.3 www.daugher 6 country Responsable of ASN

and send another e-mail.

Thanks a lot people

Moderator's Comments:
Mod Comment Please use code tags

Last edited by Scott; 06-01-2010 at 07:05 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format column datas

I have some data like this: 4258092 TRXCODE a 19 CARDNBR a 10 PINFLAG a 6 FUISSUER a 12 PRODUCT a 24 STATE n 1 I want out put this format: <?xml version="1.0" encoding="GB2312"?> <convGrp> <grpid>4258092</grpid> <script> <!]> ... (4 Replies)
Discussion started by: hhdzhu
4 Replies

2. Linux

Print each ; separated value, in front of the value preceding them

I have a file that looks like this, P38112 Q12389; Q03532; P43586; Q08208; P37838; P40693; P38805 Q12389 P32892; P36049; Q03532; P43586; Q12176; P38112; P39744; P37838 P11154 P39940 P50094 P50095 P32892 Q12389; Q04660; P43586; P37838; P40693 Q05022 Q08235; Q12176; P39744 P40347 P32333... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies

3. Shell Programming and Scripting

awk print - fields separated with comma's need to ignore inbetween double quotes

I am trying to re-format a .csv file using awk. I have 6 fields in the .csv file. Some of the fields are enclosed in double quotes and contain comma's inside the quotes. awk is breaking this into multiple fields. Sample lines from the .csv file: Device Name,Personnel,Date,Solution... (1 Reply)
Discussion started by: jxrst
1 Replies

4. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

5. Shell Programming and Scripting

Print pipe separated list as line by line in Korn Shell

Korn Shell in AIX 6.1 I want to print the below shown pipe (|) separated list line by line. line=es349889|nhb882309|ts00293|snh03524|bg578835|bg37900|rnh00297|py882201|sg175883 for i in line do echo "Hello $line " done I wanted to execute the above for loop. But i can't even set the... (3 Replies)
Discussion started by: polavan
3 Replies

6. Shell Programming and Scripting

Grep and print next 10 Lines separated by ,

Hi All, I need to grep through a file for a string and print the next ten lines to a file separating the lines with a , and save it as a csv file to open it as a XL file. The 10 lines should be on a sigle row in xl. Any suggesstions please. Note; I dont have a GNU Grep to use -A flag. ... (6 Replies)
Discussion started by: Nani369
6 Replies

7. Shell Programming and Scripting

Compare Tab Separated Field with AWK to all and print lines of unique fields.

Hi. I have a tab separated file that has a couple nearly identical lines. When doing: sort file | uniq > file.new It passes through the nearly identical lines because, well, they still are unique. a) I want to look only at field x for uniqueness and if the content in field x is the... (1 Reply)
Discussion started by: rocket_dog
1 Replies

8. Shell Programming and Scripting

Perl script to parse output and print it comma separated

I need to arrange output of SQL query into a comma separated format and I'm struggling with processing the output... The output is something like this: <Attribute1 name><x amount of white spaces><Atribute value> <Attribute2 name><x amount of white spaces><Atribute value> <Attribute3... (2 Replies)
Discussion started by: Juha
2 Replies

9. Shell Programming and Scripting

arranging datas if input file is not having also...!!

hi, my input file is containg uid, eriMaster ,eriResign, ericontry, dept. some of the uid are not having all info. out put should include all info irrespctive of datas of input file if any one data is missing, then it has to print Null or zero..then continue with the existing one. here... (0 Replies)
Discussion started by: hegdeshashi
0 Replies

10. Shell Programming and Scripting

Blank characters between Datas

Hello, I read a file whose in lines are datas and between thses datas there is blank characters (10, 12 or 5 or 1 .......) So when i use the command while read line in the script(see under) there is also only one character between the datas and the others blank characters are not here. ... (3 Replies)
Discussion started by: steiner
3 Replies
Login or Register to Ask a Question