1

I have a file with the content shown below:

***************Encrypted String***************
 ezF7LcHO0Zlb+8kkBeIwtA== 
**********************************************

I need to get only encrypted password from above. I used Google to search for an answer, and I got this example (below), but it didn't work:

sed -n '/***************Encrypted String***************/,/************************************‌​**********/p' $file

I tried but it didn't work

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • what have you tried? see http://stackoverflow.com/questions/38972736/how-to-select-lines-between-two-patterns/38978201#38978201 for an example to solve this kind of problem – Sundeep Sep 12 '16 at 12:47
  • sed -n '/BEGIN/,/END/p' $file but it did not work – Sureshchandra Jarugula Sep 12 '16 at 12:50
  • actually i need to get only encrypted password from below. While i am google it i got above example but it didn't work ***************Encrypted String*************** ezF7LcHO0Zlb+8kkBeIwtA== ********************************************** – Sureshchandra Jarugula Sep 12 '16 at 12:59
  • sed -n '/BEGIN/,/END/{/BEGIN/!{/END/!p}}' file – klerk Sep 12 '16 at 13:03
  • i need to get only encrypted password from below. While i am google it i got above example but it didn't work ***************Encrypted String*************** ezF7LcHO0Zlb+8kkBeIwtA== ********************************************** sed -n '/***************Encrypted String***************/,/**********************************************/p' $file is this works, i tryed but it didn't work – Sureshchandra Jarugula Sep 12 '16 at 13:06
  • Please put your updates into the question. Leaving them in the comments makes it confusing and ambiguous for people trying to understand which is the most recent edit. – roaima Sep 12 '16 at 15:15

1 Answers1

1

The problem here is probably that * is a Regular Expression operator, so you have to escape it \* for it to be treated as a literal. Your examples and suggestions referencing the literals BEGIN and END would all have failed without this adaptation.

***************Encrypted String***************
 ezF7LcHO0Zlb+8kkBeIwtA== 
**********************************************

To extract the second line you could use either of these:

sed -n '0,/\*Encrypted String\*/d;p;q' "$file"
sed -n 2p "$file"

The first matches on *Encrypted String* and then prints the next line. Notice that the * characters are written as \* to ensure they are treated as literal asterisks. The second just prints line two of the file.

roaima
  • 107,089
  • 14
  • 139
  • 261