Help with specific output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with specific output
# 1  
Old 02-06-2018
Help with specific output

hi folks, looking for a way to view a file and get the output of bold strings below? Thanks.

Code:
20-AUG-2017 16:14:59 * (CONNECT_DATA=(SID=TST)(CID=(PROGRAM=)(HOST=__jdbc__)(USER=xxxx))) * (ADDRESS=(PROTOCOL=tcp)(HOST=144.55.11.55)(PORT=50622)) * establish * TST * 0

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-06-2018 at 04:41 AM.. Reason: Added CODE tags.
# 2  
Old 02-06-2018
Quote:
Originally Posted by jaapar
hi folks, looking for a way to view a file and get the output of bold strings below? Thanks.
20-AUG-2017 16:14:59 * (CONNECT_DATA=(SID=TST)(CID=(PROGRAM=)(HOST=__jdbc__)(USER=xxxx))) * (ADDRESS=(PROTOCOL=tcp)(HOST=144.55.11.55)(PO
RT=50622)) * establish * TST * 0
Hello jaapar,

Could you please try following and let me know if this helps you.
Code:
awk '{match($0,/HOST=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/);if(substr($0,RSTART,RLENGTH)){print substr($0,RSTART,RLENGTH)}}'  Input_file

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 02-06-2018
If the only criterion were an IP address in dotted quad to follow the "HOST=" string, then RavinderSingh13's proposal would work fine, although it might be somewhat too cautious.
Code:
awk 'match($0,/HOST=[0-9.]+/) {print substr($0,RSTART,RLENGTH)}'  file
HOST=144.55.11.55

would do the same. But there might be additional criteria, like it should be part of the ADDRESS section, or belong to the tcp PROTOCOL, or have a certain PORT set...?
This User Gave Thanks to RudiC For This Post:
# 4  
Old 02-06-2018
Quote:
Originally Posted by RavinderSingh13
Hello jaapar,

Could you please try following and let me know if this helps you.
Code:
awk '{match($0,/HOST=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/);if(substr($0,RSTART,RLENGTH)){print substr($0,RSTART,RLENGTH)}}'  Input_file

Thanks,
R. Singh
This works like a charm. Thanks Singh!

---------- Post updated at 04:57 AM ---------- Previous update was at 04:56 AM ----------

Quote:
Originally Posted by RudiC
If the only criterion were an IP address in dotted quad to follow the "HOST=" string, then RavinderSingh13's proposal would work fine, although it might be somewhat too cautious.
Code:
awk 'match($0,/HOST=[0-9.]+/) {print substr($0,RSTART,RLENGTH)}'  file
HOST=144.55.11.55

would do the same. But there might be additional criteria, like it should be part of the ADDRESS section, or belong to the tcp PROTOCOL, or have a certain PORT set...?
This works fine, thanks Rudy!!!
# 5  
Old 02-06-2018
If you have this as a value in $var, you could also:-
Code:
echo $var | tr "()" "\n\n" | grep -E "^host="

It's a bit clunky, but might do the job you need.



Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get specific information from output

Hello community, I'm going crazy to analize an output via shell script and then get some information from it, here is the output: Slot 2 - MMU2 H, RAU2 X 15/A01 XPIC Enabled Autorestore Unknown Slot 3 - MMU2 H, RAU2 X 15/A01 XPIC ... (7 Replies)
Discussion started by: Lord Spectre
7 Replies

2. Shell Programming and Scripting

Create specific output

I have a file that looks like the below and only need certain lines, but am not sure how to do that. It is basically everything from the @HD up to the @RG. Thank you :). file.txt - input @HD VN:1.4 GO:none SO:coordinate @SQ SN:chr1 LN:249250621 @SQ SN:chr2 LN:243199373... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Need specific output from script

Hallo Team, I have *.csv files and this is the command that i run to find out how many occurances i have in this files. For example i run this command below: -bash-3.2$ grep "ACCOUNT NOT FOUND" BW-CDR-2013* |grep -v INCE|cut -f32 -d"," | sort -u BRY CORONATION-CONF DOE-CONF HIP-ADVTECH-AP... (5 Replies)
Discussion started by: kekanap
5 Replies

4. Shell Programming and Scripting

Getting specific strings from output

so i have the following string: ... (3 Replies)
Discussion started by: SkySmart
3 Replies

5. Shell Programming and Scripting

AWK specific output filename

Hi All, I'd like to create a specific output filename for AWK. The file I am processing with AWK looks like: output_081012.csv* 27*TEXT*1.0*2.0*3.0 where * is my delimeter and the first line of the file is the output filename i'd like to create is there a way to assign an awk... (10 Replies)
Discussion started by: LMSteed
10 Replies

6. Homework & Coursework Questions

Using ls or echo to display a specific output

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: What single command line would you enter to get the following output? 8140 drwxr-xr-x 9 root bin 18 Jan 20... (6 Replies)
Discussion started by: dasboot
6 Replies

7. Programming

how to output data with only an specific string on it

hi! i made an sql script but i do not know how to just output all the lines that starts with an specific string. and that string, you will input it before i run the sql for example: INPUT NAME: JOHN i just want to output lines that starts with JOHN (2 Replies)
Discussion started by: engr.jay
2 Replies

8. Shell Programming and Scripting

Screen Output to Specific Columns

User with moderate experience: I run a script (my addiction is KSH) that reads a file and reports certain parameters back to the user on screen and also piped to a file. The file(s) I read is/are located under different directories, and is usually called the same thing. Sometimes not. For... (3 Replies)
Discussion started by: Brusimm
3 Replies

9. UNIX for Advanced & Expert Users

Formatting the output to a specific design

Hi, I require some help on the following, I have a file which looks like this 123452 /root/Desktop file1 system1 system2.. systemN user1 lab1 I need to display the output like this, 123452 /root/Desktop file1 system1 user1 lab1 ... (1 Reply)
Discussion started by: kanna_geekworkz
1 Replies

10. Shell Programming and Scripting

Redirecting my output to a specific file

Hi guys am doing some checking inside my script and i want to redirect my output to a specific file for example checking if a move was successfully done and was writing on the screen whether the move was successful or not and now want to write same thing into a file... I am new to shell... (2 Replies)
Discussion started by: Lutchumaya
2 Replies
Login or Register to Ask a Question