Get distinct value in bash between two string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get distinct value in bash between two string
# 1  
Old 02-22-2016
Get distinct value in bash between two string

Sorry for my english i am french

So i am receiving from a script this prompt :
Code:
tabular;critical;mirroring;DG INTlocaldg VOLUME appears
tabular;critical;mirroring;DG INTlocaldg VOLUME bh3vm
tabular;critical;mirroring;DG INTlocaldg VOLUME dev
tabular;critical;mirroring;DG INTlocaldg VOLUME earsdev
tabular;critical;mirroring;DG INTlocaldg VOLUME earslivraison
tabular;critical;mirroring;DG INTlocaldg VOLUME earsrct
tabular;critical;mirroring;DG INTlocaldg VOLUME ed
tabular;critical;mirroring;DG INTlocaldg VOLUME eng
tabular;critical;mirroring;DG INTlocaldg VOLUME home
tabular;critical;mirroring;DG INTlocaldg VOLUME home_Ctibco6
tabular;critical;mirroring;DG INTlocaldg VOLUME home_adapter
tabular;critical;mirroring;DG INTlocaldg VOLUME icf
tabular;critical;mirroring;DG INTlocaldg VOLUME investigation
tabular;critical;mirroring;DG INTlocaldg VOLUME isa_dev
tabular;critical;mirroring;DG INTlocaldg VOLUME isa_rct
tabular;critical;mirroring;DG INTlocaldg VOLUME isa_share
tabular;critical;mirroring;DG INTlocaldg VOLUME livraison
tabular;critical;mirroring;DG INTlocaldg VOLUME mq
tabular;critical;mirroring;DG INTlocaldg VOLUME mqlog
tabular;critical;mirroring;DG INTlocaldg VOLUME mqprod
tabular;critical;mirroring;DG INTlocaldg VOLUME mqvar
tabular;critical;mirroring;DG INTlocaldg VOLUME netbackup
tabular;critical;mirroring;DG INTlocaldg VOLUME od-home
tabular;critical;mirroring;DG INTlocaldg VOLUME oracle
tabular;critical;mirroring;DG INTlocaldg VOLUME oradb
tabular;critical;mirroring;DG INTlocaldg VOLUME ov
tabular;critical;mirroring;DG INTlocaldg VOLUME rct
tabular;critical;mirroring;DG INTlocaldg VOLUME rc3
tabular;critical;mirroring;DG INTlocaldg VOLUME sar
tabular;critical;mirroring;DG INTlocaldg VOLUME soa
tabular;critical;mirroring;DG INTlocaldg VOLUME tibbh3
tabular;critical;tibco;DG INTlocaldg VOLUME tibco
tabular;critical;tibco;DG INTlocaldg VOLUME tibco_dev6
tabular;critical;tibco;DG INTlocaldg VOLUME tibco_rc2
tabular;critical;tibco;DG INTlocaldg VOLUME tibcobh3
tabular;critical;mirroring;DG INTlocaldg VOLUME tws00
tabular;critical;mirroring;DG INTlocaldg VOLUME unix
tabular;critical;was;DG INTlocaldg VOLUME was6
tabular;critical;was;DG INTlocaldg VOLUME was6dev
tabular;critical;was;DG INTlocaldg VOLUME was6devcells
tabular;critical;was;DG INTlocaldg VOLUME was6devlogs
tabular;critical;was;DG INTlocaldg VOLUME was6devproduct
tabular;critical;was;DG INTlocaldg VOLUME was6distrib
tabular;critical;was;DG INTlocaldg VOLUME was6rct
tabular;critical;was;DG INTlocaldg VOLUME was6rctcells
tabular;critical;was;DG INTlocaldg VOLUME was6rctlogs
tabular;critical;was;DG INTlocaldg VOLUME was6rctproduct
tabular;critical;was;DG INTlocaldg VOLUME was6share

I need to get the list of my error type
Basicly i need to get distinct value between 'critical'; and the third ';'
was
tibco
mirroring

in this exemple, but i can have lot of more.

Can i do this with one command, or should i put all in one table and compare every value ?
# 2  
Old 02-22-2016
Hello cterra,

Welcome to the forums, special thanks for using the code tags as per forum rules Smilie.
Could you please try following and let me know if this helps you. On a Solaris/SunOS system,
change awkto /usr/xpg4/bin/awk , /usr/xpg6/bin/awk, or nawk.
Code:
awk -F";" '{A[$3]} END{for(i in A){print i}}'  Input_file

Output will be as follows.
Code:
was
mirroring
tibco

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 02-22-2016
Or
Code:
awk '!L[$3]++{print $3} ' FS=";" file
mirroring
tibco
was

# 4  
Old 02-22-2016
Quote:
Originally Posted by RavinderSingh13
Code:
awk -F";" '{A[$3]} END{for(i in A){print i}}'  Input_file

Perfect, it s exactly what i am looking for, it will be run only on linux, thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Escape bash-special character in a bash string

Hi, I am new in bash scripting. In my work, I provide support to several users and when I connect to their computers I use the same admin and password, so I am trying to create a script that will only ask me for the IP address and then connect to the computer without having me to type the user... (5 Replies)
Discussion started by: arcoa05
5 Replies

2. Shell Programming and Scripting

Bash: Getting first digit of a string

If i'm given a string like "abc-def-1.2.3", how would I return "1"? I'm new to scripting and got stumped on this problem. Thanks in advance! (7 Replies)
Discussion started by: atsim
7 Replies

3. Shell Programming and Scripting

Bash Integers/String

Hy friends, I am newbie to bash scripting, can anyone explain how b=${a/23/BB} # Substitute "BB" for "23". this line converts "b" into string and and "d" into Integer. Thanks in advance (4 Replies)
Discussion started by: Qazi
4 Replies

4. Shell Programming and Scripting

How do a distinct from a file using sort uniq in bash?

I have an output file .dat. From this file i have to do a distinct of the ID using the sort uniq command in bash script. How can i do it? i found : sort -u ${FILEOUT_DAT} but i don't think is my solution because the id isn't specified.. is there other solution? (7 Replies)
Discussion started by: punticci
7 Replies

5. Shell Programming and Scripting

Bash string manipulation

In my script I'm retrieving a parameter through an API call. I need to trim some things out of the result so I can use it as a parameter to pass to another process. I've got it working but it's pretty kludgy and I'm hoping someone can help me with a better way. This is the code that retrieves... (2 Replies)
Discussion started by: withanh
2 Replies

6. Shell Programming and Scripting

bash string manipulation

Hello guys, here is my problem: I got a shell script which is called by an external piece of software, the external software is not under my control. The software passes data as an argument to my script like ./bla.sh 'service;1234567890;ok;hostname;some text here' I need to pass the... (3 Replies)
Discussion started by: snoogie
3 Replies

7. Shell Programming and Scripting

Get the distinct string from file.

my question is , i want to get the distinct email address from the file which contains: <Email address>|<file name> /tmp/test.log petercs@yahoo.com|sf1.pdf sandycs@yahoo.com|sf2.pdf davidcs@yahoo.com|sf3.pdf davidcs@yahoo.com|sf4.pdf i want to get the result like: petercs@yahoo.com... (5 Replies)
Discussion started by: bearonweb
5 Replies

8. Shell Programming and Scripting

String comparison using bash

I have a program to create a directory if not present. Here is the program. FYI: Directory name format: YYYY_MM_DD #!/bin/bash date=`date +%Y_%m_%d` presence=$(ls -lrt /TS_File/ | grep "$date" | awk '{print $9}') if then mkdir /TS_File/$date else echo "Unable to Create... (5 Replies)
Discussion started by: nthiruvenkatam
5 Replies

9. Shell Programming and Scripting

Bash string replace

Bash shell. I'm trying to filter a string taken from user input. I can replace one word at a time. This method supports regex, so is it possible to replace various words at a time? STRING="Hello World! word1 word2"; FILTERED=${STRING/word1|word2/}; # Not working: replace 2 or more words ??? ... (10 Replies)
Discussion started by: limmer
10 Replies
Login or Register to Ask a Question