Trying to grab a record when column meets condition.
Code:
$1=file As the seasoned Admins know it is not doing what I want it to. Instead once the condition is met all the record are being printed out. Any help or direction would be greatly appreciated. I look forward to your input. s |
First of all, just to be certain, we are talking about shell scripting here?
Code:
$1=file Code:
case Code:
case $1 in Code:
for i in $file Code:
for var in <list>; do Also, QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later. http://mywiki.wooledge.org/Arguments http://mywiki.wooledge.org/WordSplitting http://mywiki.wooledge.org/Quotes awk cannot generally use shell variables directly. You have to import them into awk variables using the -v option. Finally, there's the Useless Use Of Grep, but that's a minor problem compared to the rest. Here are a few useful bash scripting references: http://mywiki.wooledge.org/BashGuide http://wiki.bash-hackers.org/start http://www.linuxcommand.org/index.php http://wiki.bash-hackers.org/scripting/newbie_traps http://mywiki.wooledge.org/BashPitfalls http://mywiki.wooledge.org/BashFAQ http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/index.html http://www.gnu.org/software/bash/manual/bashref.html http://ss64.com/bash/ I suggest reading through the first one carefully, at least. Here are a few useful awk references: http://www.grymoire.com/Unix/Awk.html http://www.gnu.org/software/gawk/man...ode/index.html http://www.pement.org/awk/awk1line.txt http://www.catonmat.net/blog/awk-one...ined-part-one/ |
Here is where we are after your edits.
Code:
file=$1 Code:
case var in Hopefully that clears somethings up. |
You appear to be quite confused about how awk and the various shell features actually work.
Let's start over from the beginning. Forget about what you've written so far and simply explain exactly what you are trying to do, in reasonable detail, along with a representative example of the input text. Then explain exactly what you want to extract from it, according to what criteria and in what format, and where the matching values are to come from, if any. I'm pretty sure that your requirements can be met with just a simple awk command, perhaps with a small shell wrapper if you need to match multiple values. But it all comes down to the details. |
All times are GMT -5. The time now is 03:49 AM. |