syamkp
March 28, 2008, 3:50am
1
Hi,
I have a long string like,
aabab|bcbcbcbbc|defgh|paswd123 dedededede|efef|ghijklmn|paswd234 ghghghghgh|ijijii|klllkkk|paswd345 lmlmlmmm|nononononn|opopopopp|paswd456
This string is devided into one space between substrings. This substrings are,
aabab|bcbcbcbbc|defgh|paswd123
dedededede|efef|ghijklmn|paswd234
ghghghghgh|ijijii|klllkkk|paswd345
lmlmlmmm|nononononn|opopopopp|paswd456
Now i want to get paswd234 by searching corresponding ghijklmn
similarly want to get paswd345 by searching corresponding klllkkk
But above long string is dynamic, means may be some more substrings can add to this long string or may be some substrings can be removed from this long string.
could any one pls help me in this.
Thanks in advance.
syamkp
March 28, 2008, 4:13am
2
Forgot to mention one thing, In this long string
aabab|bcbcbcbbc|defgh|paswd123 dedededede|efef|ghijklmn|paswd234 ghghghghgh|ijijii|klllkkk|paswd345 lmlmlmmm|nononononn|opopopopp|paswd456
sometimes paswd234(8 chars) length may get change to less or more of 8 chars. Means the long string may be like,
aabab|bcbcbcbbc|defgh|passwd123 dedededede|efef|ghijklmn|pasd234 ghghghghgh|ijijii|klllkkk|pd345 lmlmlmmm|nononononn|opopopopp|passswwd456
vino
March 28, 2008, 4:31am
3
syamkp:
Hi,
I have a long string like,
aabab|bcbcbcbbc|defgh|paswd123 dedededede|efef|ghijklmn|paswd234 ghghghghgh|ijijii|klllkkk|paswd345 lmlmlmmm|nononononn|opopopopp|paswd456
This string is devided into one space between substrings. This substrings are,
aabab|bcbcbcbbc|defgh|paswd123
dedededede|efef|ghijklmn|paswd234
ghghghghgh|ijijii|klllkkk|paswd345
lmlmlmmm|nononononn|opopopopp|paswd456
Now i want to get paswd234 by searching corresponding ghijklmn
similarly want to get paswd345 by searching corresponding klllkkk
Do you want password for ghijklmn and klllkkk alone or do you want all the passwords ?
For all passwords
tr ' ' '\n' < input.txt | sed -n -e "s/.*|\(.*\)/\1/p"
syamkp
March 28, 2008, 5:33am
4
Thanks for your solution Vino,
I want pasword for individual. Actually i will give only one search string and want to fetch corresponding pasword for one execution of the command.
for example,
the search string is ghijklmn
and i want corresponding pasword.
era
March 28, 2008, 5:58am
5
Then modify the sed script to only print when that particular key is matched.
vino
March 28, 2008, 7:34am
6
syamkp:
Thanks for your solution Vino,
I want pasword for individual. Actually i will give only one search string and want to fetch corresponding pasword for one execution of the command.
for example,
the search string is ghijklmn
and i want corresponding pasword.
string=ghijklmn
sed -n -e "s/.*${string}|\([^ ]*\) .*/\1/p" input.txt
But I think you would be better off with this sed statement and the above tr statement. Lest you dont run into a command too long.
syamkp
March 31, 2008, 2:08am
7
Thanks for your replies vino
your command is working fine.
but i am sorry, i didnt give correct input string. it is like,
aab.a0b|bcbc1bcbbc|de_f2gh|paswd123 dede.ded.ede|ef_ef|ghi_jklm0n|paswd234 gh.ghgh.ghgh|ijijii|k_ll4lkkk|paswd345 lml.mlmmm|nononononn|op_opop_opp0|paswd456
This string is having . and _ so couldnt get result for me.
can you pls take the above string as an input string and can you give the command.