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

6
  • what have you tried? see stackoverflow.com/questions/38972736/… for an example to solve this kind of problem Commented Sep 12, 2016 at 12:47
  • sed -n '/BEGIN/,/END/p' $file but it did not work Commented Sep 12, 2016 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== ********************************************** Commented Sep 12, 2016 at 12:59
  • sed -n '/BEGIN/,/END/{/BEGIN/!{/END/!p}}' file Commented Sep 12, 2016 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 Commented Sep 12, 2016 at 13:06

1 Answer 1

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.