SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


scriptgrepusefulllinesasmatchingpattern
Differences

This shows you the differences between two versions of the page.

Link to this comparison view

scriptgrepusefulllinesasmatchingpattern [2013/05/18 09:25] (current)
sjoerd created
Line 1: Line 1:
 += Script: Bash: Use Full Lines From Inputfile as Matching Pattern =
  
 +Usecase: Use an inputfile from which the full line is used as a search pattern in other files. The other files all start with SHIFT. The inputfile lines contain whilespaces. ​
 +
 +<​code>​
 +inputfile=/​tmp/​inputfile.txt
 +
 +nlines=`cat $inputfile | wc -l`
 +teller=1
 +while [[ $teller -lt $nlines ]]; do
 +        match=`head -$teller $inputfile | tail -1`
 +        grep "​$match"​ SHIFT* > /dev/null
 +        if [ $? -eq 0 ]; then
 +                echo $match still exists!
 +        fi
 +        teller=$(($teller+1))
 +done
 +</​code>​
 +
 +Explained code:
 +<​code>​
 +inputfile=/​tmp/​inputfile.txt
 +
 +# Count the number of lines in the inputfile. This is the number of times the loop will be gone through. ​
 +nlines=`cat $inputfile | wc -l`
 +teller=1
 +while [[ $teller -lt $nlines ]]; do
 +        # Use head and tail to set a variable with a complete line from the inputfile
 +        match=`head -$teller $inputfile | tail -1`
 +        grep "​$match"​ SHIFT* > /dev/null
 +        if [ $? -eq 0 ]; then
 +                echo $match still exists!
 +        fi
 +        teller=$(($teller+1))
 +done
 +</​code>​
 +
 +
 +{{tag>​scripts}}
scriptgrepusefulllinesasmatchingpattern.txt ยท Last modified: 2013/05/18 09:25 by sjoerd