Skip to main content
1 of 7
jevan
  • 41
  • 1
  • 5

I need to find a line/word, but need to print only the line above it... In loop. How to do it suggest me guys

I need to find a line but need to print the line above it.

ie) consider a file containing

$cat > para returns between the paragaraphs

italic or bold

quotes by placing

italic

Here i need to find for italic, and i need to get the output as below

returns between the paragaraphs

quotes by placing

I tried using

  1. cat para|grep -B1 italic it giving an output as

returns between the paragaraphs

italic or bold

quotes by placing

italic

  1. cat para|grep -B1 italic |head -1 it giving an output as

returns between the paragaraphs

  1. i have tried combination of grep and cat

cat >last

cat para|grep -B1 italic >last

cat last|grep -v italic

Now i'm getting the right output

returns between the paragaraphs

quotes by placing

Now my question is there any other way to get the same output ??? Please help me on this guys...

jevan
  • 41
  • 1
  • 5