![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Parameters in loop | mgirinath | Shell Programming and Scripting | 3 | 03-18-2008 10:20 AM |
| Urgent:Comparing two Strings using If Loop | Anji | Shell Programming and Scripting | 2 | 01-09-2008 08:54 AM |
| Read from a file and use the strings in a loop | xboxer21 | Shell Programming and Scripting | 3 | 04-18-2006 03:30 PM |
| How to concatenate two strings or several strings into one string in B-shell? | fontana | Shell Programming and Scripting | 2 | 08-26-2005 11:58 AM |
| how to get the similar function in while loop or for loop | trynew | Shell Programming and Scripting | 3 | 06-17-2002 11:09 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
For Loop with Strings as parameters
I'm trying to create a script with a for loop that take strings in as the parameters. Some of the strings have spaces in them, and I can't get it to work properly. For example:
Code:
#!/bin/ksh
INFILE=snapshot.log
OUTFILE=summary.out
a="Lock waits"
b="Deadlocks detected"
for PARAM in ${a} ${b}
do
/usr/bin/grep ${PARAM} ${INFILE} >> ${OUTFILE}
done
1st pass - Lock 2nd pass - waits 3rd pass - Deadlocks 4th pass - detected I've tried placing the strings in single and double quotes, but that doesn't seem to help. Any ideas? |
|
||||
|
I donīt know a lot of english and i will to try to explain it. If you have more questions you can ask again
. Ok the system has a variable, that for loop uses to know how many parameters has the file for example a text. The variable has space, tabs and return (of course all convinations of that).THE ANSWER $cat > example spaces=IFS #IFS is the system variable IFS=" #We inicializating IFS=return to tae all the line " ........................ ........................ IFS=$spaces #We used the var spaces to give the value to IFS againwhen we finish unset spaces Bye |
|
||||
|
Thanks for everyone's suggestions. I finally got it working:
Code:
OUTFILE=summary.out
a='Deadlocks detected'
b='Lock escalations'
for PARAM in "${a}" "${b}"
do
echo ${PARAM}
COUNT=1
while ((COUNT < 41))
do
INFILE=DB2Snapshot_${1}_${COUNT}.log
/usr/bin/grep "${PARAM}" ${INFILE} >> ${OUTFILE}
((COUNT=COUNT+1))
done
done
|
|
||||
|
getting spaces while reading file from for loop
Hi ,
I am getting similar problem, but in my case i am fetching variable value from a file , and then echo the value, but its considering spaces in the file. for exmp: file - temp1 has contents in quotes "group name used to communicate with x service" "group name used to communicate with y service" i used for loop : for var in `cat "temp1"` do echo "DESC=$var;" done the desired output is DESC="group name used to communicate with x service"; DESC="group name used to communicate with y service"; however, the output coming is DESC="group"; DESC="name"; its reading spaces also... Pls suggest............... Thanks in advance Aparna |
| Sponsored Links | ||
|
|