Extracting and printing data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting and printing data
# 8  
Old 01-18-2011
$0=$5" "$7Make $0 equal to $5 and $7 with a space in between
!A[$0]++if A[$0]=0 or "" then perform the default action, i.e. print $0. Afterwards increment the value of A[$0] (++)
# 9  
Old 01-19-2011
Thanks for reponse Scrutinizer.

!A[$0]++ if A[$0]=0 or "" then perform the default action, i.e. print $0. Afterwards increment the value of A[$0] (++)

Sorry to be a pain but how does( if A[$0]=0 or "") check for uniqueness and how does incrementing A[$0] (++) fit in.

From my understanding $0 is stored in an array,it than needs to be checked if the value already exist in the array if does not print it so i get lost at the the A[$0]++ part.is this adding it the unique value to the array which will later be checked again

Once again Sorry - Your code works perfectly I just need to get the hang arrays

Thanks


A[$0]++if A[$0]=0 or "" then perform the default action, i.e. print $0. Afterwards increment the value of A[$0] (++)

A[$0]++if A[$0]=0 or "" then perform the default action, i.e. print $0. Afterwards increment the value of A[$0] (++)
# 10  
Old 01-19-2011
Hi, the first time $5 and $7 contain a combination of values array, for example BTS:34 and Cell:34A, then A[BTS:34 Cell:34A] does not contain a value, so the values get printed. Afterwards the value gets incremented, so A[BTS:34 Cell:34A] then contains the value 1. Each subsequent line where the $5 and $7 are present will not get printed (because it is not 0 or "") and the corresponding array value will be incremented.

Incrementing is just one thing, I could have done this too:


This would be another - less compact way - of accomplishing the same thing:
Code:
awk -F'[/"]' '{if(!A[$5,$7]){print $5,$7; A[$5,$7]=A[$5,$7]+1}}' infile

or
Code:
awk -F'[/"]' '{if(!A[$5,$7]){print $5,$7; A[$5,$7]=1}}' infile


Last edited by Scrutinizer; 01-19-2011 at 01:34 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with extracting data within parentheses

This is my input file: a|b|c(ef)|g|h(km)|p My output file should look like: a|b|ef|g|km|p That is, pipe is the delimiter. The data within pipe must be displayed as it is but if it encounters any data within parentheses, then only the data within parentheses has to be displayed ( the data... (2 Replies)
Discussion started by: ksatish89
2 Replies

2. Shell Programming and Scripting

Q:Perl Extracting & Printing Security Token

I have a script which is supposed to log in to my vB account and print my security token, however doesn't seem to work globally. The logging in works perfectly just will not retrieve and print the security token for every forum I log in to. Code Below: #!/usr/bin/perl use LWP::UserAgent; ... (8 Replies)
Discussion started by: AndrewTwain
8 Replies

3. UNIX for Dummies Questions & Answers

Extracting data from file

I am trying to compare the data in lines 3 & 5 to see if they match up to the '-S570' (see first code set, all proprietary information has been removed from code set) spawn telnet Trying ... Connected to CA-LOS1234-ASE-S570.cl . Escape character is '^]'. CA-LOS1234-ASE-S570 Username: ... (1 Reply)
Discussion started by: slipshft
1 Replies

4. Shell Programming and Scripting

extracting data

I have a txt file of the following format >ab_ qwerty >rt_ hfjkil >Ty2 hglashglkasghkf; >P2 aklhfklflkkgfgkfl >ui_ vnllkdskkkffkfkkf >we32 vksksjksj;lslsf'sk's's .... ..... I want to split this big file based on the header (>) (5 Replies)
Discussion started by: Lucky Ali
5 Replies

5. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

6. Shell Programming and Scripting

extracting data from a string

Hi there, I have a bunch of vlan tagged network interfaces that are named as follows e1000g111000 e1000g99001 e1000g3456000 nge2002 where the 'e1000g' and 'nge' parts of the name are the driver, the red and blue bits above define the VLAN and the last digit on the end defines the... (3 Replies)
Discussion started by: rethink
3 Replies

7. Shell Programming and Scripting

Extracting data from tables......

HOw to extracts data from tables in database. Merges them into one output file. This output file is loaded into another tables in database. (1 Reply)
Discussion started by: nari.bommi
1 Replies

8. UNIX for Dummies Questions & Answers

Help with extracting data and plotting

I have attached a txt file, what I would like to be able to do is: 1. Extract Data from Columns labeled E/N and Ko into a new file 2. Then in the new file I would like to be able to plot E/N on the X axis and Ko on the y axis. 3. Lastly I would like to be able to extract multiple data sets and... (6 Replies)
Discussion started by: gingburg
6 Replies

9. Shell Programming and Scripting

Extracting Data From Sendmail

Hello, Like many Unix shops, Our systems send Email alerts whenever things break. I have been tasked with writing a shell script to get the email alerts from Sendmail, extract the Date / Time, From, Subject, and message text from the emails and punch them into a MySQL DB. This will then be... (3 Replies)
Discussion started by: calex
3 Replies

10. Shell Programming and Scripting

Extracting certain data from a sentence

How do I delete text in each line from the first character up to a certain pattern, ie. 'qmuser.' and then delete from the next occurence of a dot to the end of the sentence For example: - LTSB Renewal Notice Travel Pack --- d \qmaster\spool1\qmuser.8664_LM245_20031216094308.ps.0 From this... (7 Replies)
Discussion started by: dbrundrett
7 Replies
Login or Register to Ask a Question