-2

i want to extract strings patterns from a file . My input file looks like this :

Name = Apple Is Red
Hidden = True
Name = Banana Is Yellow
Hidden = False
Name = Orange Is Orange
Hidden = True
Name = Guava Is Green
Hidden = False

What i want in the output is it will create two files one with true.log & false.log :

true.log

Name = Apple is Red
Hidden = True
Name = Orange Is Orange
Hidden = True

false.log

Name = Banana Is Yellow
Hidden = False
Name = Guava Is Green
Hidden = False

New at bash scripting and Linux .

rojomoke
  • 2,965
  • 1
  • 17
  • 26
  • Name = blah blah (line break) Hidden = True (line break) Name = foo foo (line break) Hidden = False (line break) file is in this format – AhmedOmair Sep 03 '15 at 10:09

2 Answers2

0

Simple grep with -B (before context)

grep -B1 --no-group-separator 'Hidden = True' myfile

(--no-group-separator so there is no superfluous hyphens)

pacholik
  • 7,596
  • 8
  • 43
  • 50
-2

Try

apple=$(cut inputfile -d"=" -f2) #what stands after the = into a variable apple
if [ $apple = "Apple Is Red" ] ; then
    echo "Hidden = true" >> true.txt
fi

Edit: sry my connection hang up