Find associated strings in a bash shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find associated strings in a bash shell script
# 8  
Old 08-08-2011
Nice bash shell solution danmero.

Here is one using awk:
Code:
awk -F[.,=] '
   NF && $(NF-1) == "user" { usr=$NF}
   NF && $(NF-1) == "password" { print usr " "$NF } ' infile

This User Gave Thanks to Chubler_XL For This Post:
# 9  
Old 08-08-2011
Thank you I will try it out !! and let you know :-)
Thank you
# 10  
Old 08-08-2011
For a disordered list i'll opt for:
Code:
awk -F[.=] '!NF{next}$(NF-1)=="user"{x=$NF;sub($(NF-1)"="$NF,y);a[$0]=x}$(NF-1)=="password"{x=$NF;sub($(NF-1)"="$NF,y);if(a[$0])b[$0]=x}a[$0] && b[$0]{print a[$0],b[$0]}' file

This User Gave Thanks to danmero For This Post:
# 11  
Old 08-08-2011
My solution missed a requirement:
=> for a belonging together pair for example "admin.user/admin.password" the preceding text (for example "text4") is always the same (the same for the accompanying "access user")

This update should address that:

Code:
awk -F[.,=] '
   NF && $(NF-1) == "user" { usr=$NF; sub("user=.*","");pre=$0}
   NF && $(NF-1) == "password" && pre &&
   substr($0,0,length(pre)) == pre { print usr " "$NF;pre = ""} ' infile

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

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

Different behavior between bash shell and bash script for cmd

So I'm trying to pass certain json elements as env vars and use them later on in a script. Sample json: JSON='{ "Element1": "file-123456", "Element2": "Name, of, company written in, a very weird way", "Element3": "path/to/some/file.txt", }' (part of the) script: for s... (5 Replies)
Discussion started by: da1
5 Replies

3. Shell Programming and Scripting

Perl script to find process and exclude strings from the output

Hi team, I'm a newbie of Perl Script and looking to create a simple perl script that will run in the Linux system: 1) to find process, such as ps -ef | grep process name 2) to exclude strings from the output if it found, for instance if i see abc from usr process, then will exclude it from... (1 Reply)
Discussion started by: hoffman2503
1 Replies

4. Shell Programming and Scripting

Script to find NOT common strings in two files

Hi all, I'd like you to help or give any advise about the following: I have two (2) files, file1 and file2, both files have information common to each other. The contents of file1 is a subset of the contents of file2: file1: errormsgadmin esdp esgservices esignipa iprice ipvpn irm... (18 Replies)
Discussion started by: hnux
18 Replies

5. Shell Programming and Scripting

Script to find NOT common strings in two files

Hi all, I'd like you to help or give any advise about the following: I have two (2) files, file1 and file2, both files have information common to each other. The contents of file1 is a subset of the contents of file2: file1: errormsgadmin esdp esgservices esignipa iprice ipvpn irm... (0 Replies)
Discussion started by: hnux
0 Replies

6. Shell Programming and Scripting

Simple script to find common strings in two files

Hi , I want to write a simple script. I have two files file1: BCSpeciality Backend CB CBAPQualDisp CBCimsVFTRCK CBDSNQualDisp CBDefault CBDisney CBFaxMCGen CBMCGeneral CBMCQualDisp file2: CSpeciality Backend (8 Replies)
Discussion started by: ramky79
8 Replies

7. Shell Programming and Scripting

Find out the day in Bash Shell script

Hello All, I need a bash shell script to find out a day from the date.For example we give the date(20100227/YYYYMMDD) then we get the day 'Saturday'. Thanks in advance, Satheesh (5 Replies)
Discussion started by: satheesh4093
5 Replies

8. Shell Programming and Scripting

Quoting issue: Trouble with bash strings in script

I can do this on the command line: sqsh -S 192.168.x.x -o tmp -U user -P fakepass -D horizon -C "\ select second_id from borrower where btype like '%wsd%' " I can also just leave the SQL at the end intact on one line .... ... However, when I throw this in a script like: $SQSH -o... (4 Replies)
Discussion started by: Bubnoff
4 Replies

9. Shell Programming and Scripting

Shell script to replace strings to and from a file

Hello All, I have 2 files 1 ) source file eg asasa 1.2.3.4 adfhsdfsdfasdf zxzxzx 2.3.4.56 dsadasdasdsadasd kjjkjkjk 30.3.4.5 asdsadsadsadsadsad vxcvxcvx 1.2.3.4 qwewqewqeqweqwe 2) patern file 1.2.3.4 A 2.3.4.56 B 30.3.4.5 C I need the source to be changed to asasa A... (2 Replies)
Discussion started by: nitinkgoud
2 Replies

10. Homework & Coursework Questions

strings in shell script!

hi ppl, I have a basic doubt as to how shell treats strings. e.g:given a line of data like this "5","6","45","77","89" extracting the value from each field to a variable will conatin a string("5") or just the number? If it conatins "5", how do we perform mathematical operations with that... (3 Replies)
Discussion started by: beetel
3 Replies
Login or Register to Ask a Question