How do i get all the values ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do i get all the values ?
# 1  
Old 11-13-2009
MySQL How do i get all the values ?

Hello All

These are diffrent columns in my fingerprinting tool.Look at code lines pls.

DUP

Code:
/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|sed -n '2,$p'|awk '{print $1$2}'

Protocol

HTML Code:
echo "udp"
Local IP

HTML Code:
A=$(/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|awk -F' ' '{if ($1$2 == "@@Host NWStats.DUP@@" ) print $1}')

B=`echo "$A"|grep "*"|wc -l`

if [ $B = 1 ]
then
C=`echo "$A"|cut -d "." -f1`
echo "$C"
fi

if [ $B = 0 ]
then
D=`echo "$A"|cut -d "." -f1-4`
echo "$D"
fi

Local Port

HTML Code:
A=$(/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|awk -F' ' '{if ($1$2 == "@@Host NWStats.DUP@@" ) print $1}')

B=`echo "$A"|grep "*"|wc -l`

if [ $B = 1 ]
then
C=`echo "$A"|cut -d "." -f2`
echo "$C"
fi

if [ $B = 0 ]
then
D=`echo "$A"|cut -d "." -f5`
echo "$D"
fi
Remote IP

HTML Code:
echo "NULL"
Remote Port

HTML Code:
echo "NULL"
State

HTML Code:
A=$(/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|awk -F' ' '{if ($1$2 == "@@Host NWStats.DUP@@" ) print $2}')

echo "$A"

Issue:

Above lines have been written to get all UDP data in a CSV.

e.g
HTML Code:
bash-3.00$ /usr/bin/netstat -an -f inet -P udp

UDP: IPv4
   Local Address        Remote Address      State
-------------------- -------------------- ----------
      *.48517                             Idle
      *.*                                 Unbound
      *.161                               Idle
      *.111                               Idle
      *.*                                 Unbound
      *.33270                             Idle
      *.*                                 Unbound
      *.*                                 Unbound
      *.33271                             Idle
      *.4045                              Idle
      *.5000                              Idle
      *.5000                              Idle
      *.5000                              Idle
When i run the code,it fumbles up at these three lines

HTML Code:
      *.5000                              Idle
      *.5000                              Idle
      *.5000                              Idle
because both colmuns in all 3 rows are identical.

How can i modify code lines to capture all three rows as it is?

I am facing same issue for capturing data for TCP

HTML Code:
/usr/bin/netstat -an -f inet -P tcp

I want the commands data as it is in my CSV ,without losing any of it?

Kindly advice.

Regards
Abhi

Last edited by ak835; 11-13-2009 at 11:53 AM..
# 2  
Old 11-13-2009
You are using "uniq" in your pipeline.

If you need it for some other reason (sorry, too much stuff to look at up there!) you need to do something to modify those kinds of lines before they hit "uniq" and (if necessary) undo the changes after.

By the way, "sort -u" eliminates "sort | uniq".

Last edited by TonyLawrence; 11-13-2009 at 11:42 AM.. Reason: spelling
# 3  
Old 11-13-2009
MySQL

i was trying 'sort|uniq' just for R&D.....

i am not suppose to use it as i would be losing data (even if its identical)..


thanks for 'sort -u' !!

Regards
Abhi
# 4  
Old 11-15-2009
Code:
/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|sed -n '2,$p'|awk '{print $1$2}'

Can be changed to:

Code:
/usr/bin/netstat -an -f inet -P udp|awk 'NR>1 && ! (/UDP/||/Local/||/--/)  {print $1$2}'

# 5  
Old 11-17-2009
MySQL

thanks for 'awk' !!

though i am still stuck at the same problem.I am unable to get all the values seen ,as it is,in the CSV.

Regards
Abhi
# 6  
Old 11-18-2009
please show sample of your csv file, and the desired output.
# 7  
Old 11-18-2009
Bug

well...it worked !!

initially i had copied 'awk' statement of yours into code lines for all columns...it did not work...and then i kept it only in DUP column and used 'sort -u' in rest of the columns and bingo !!

i am now able to capture all identical rows as well....

thanks again !!


Regards
Abhi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

2. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

3. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

4. Shell Programming and Scripting

Converting odd values to even values(or vice-versa) located in a column

Hello All, I have a below data in a .csv file where all rows where col1 is A, col2 is odd numbers, similarly even numbers for all rows where col1 is B. Note that my data has some other columns(not shown here) too (around 100) after col2. Tool,Data A,1 A,3 A,5 .... so on B,2 B,4 .... ... (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

6. Shell Programming and Scripting

Get values from different columns from file2 when match values of file1

Hi everyone, I have file1 and file2 comma separated both. file1 is: Header1,Header2,Header3,Header4,Header5,Header6,Header7,Header8,Header9,Header10 Code7,,,,,,,,, Code5,,,,,,,,, Code3,,,,,,,,, Code9,,,,,,,,, Code2,,,,,,,,,file2... (17 Replies)
Discussion started by: cgkmal
17 Replies

7. Shell Programming and Scripting

Cat Values from Several files if it meets criteria for column values

I have results from some statistical analyses. The format of the results are as given below: I want to select lines that have a p-value (last column) less than 0.05 from all the results files (*.results) and cat to a new results file. It would be very nice if a new column is added that tells... (2 Replies)
Discussion started by: genehunter
2 Replies

8. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

9. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

10. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies
Login or Register to Ask a Question