|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
how to match line that contian
I have two variable that contain
$1 = unix $2 = bjc now I want to match any lines in my file that contain those variable, the lines is separated by comma Example window,bjc 210,computer unix, bjc 210, computer from the two line example above I want to print unix, bjc 210, computer |
|
#2
|
|||
|
|||
|
Grep (and/or egrep) are the tools to use. Example:
Code:
#!/bin/bash INFILE="infile" PLATFORM="unix" TYPE="bjc" grep $PLATFORM $INFILE | grep $TYPE The last line does what you want. The first part looks for 'unix' ($PLATFORM) in every line of input from 'infile' ($INFILE). If a hit is found, the second part checks to see if that line also contains 'bjc' ($TYPE). If this is the case the line is printed, if not, grep checks the next line of input. One tip: Do not use $1, $2 etc to store variables. These are special and hold information about the program and parameters. I used 'human readable' names for the variables (PLATFORM and TYPE). Hope this gets you going again. |
|
#3
|
|||
|
|||
|
Quote:
Thanx |
![]() |
| Viewing: Dev Shed Forums > Web Site Management > Scripts > how to match line that contian |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|