I have a variable which stores a string, the output of a sed command. I want to execute a set of commands only if this string value matches either of the 2 other strings.  I used the below code.   #! /bin/ksh request=”Request” fault=”Fault” while read lines; do     category=`echo $lines|sed -n -e 's/.*Summary: Value//p'| awk '{print $1}'`     if [ ! -z "$category" ]     then         if($category = $request)         then             echo $category         fi      fi done&lt;content.txt   But it's giving me an error:  sample.sh: Request: not found   The variable category will have either value Request or value Order  Can someone point the error or a solution to this?  If inner if is eliminated and echo $category will print the exact string value.
3014
I am using the below script to move two days back when script runs at starting two days of the year and also check first and second days of every month and move two days back. if [$month=&quot;01&quot;] &amp;&amp; [$day=&quot;01&quot;]; then         date=&quot;$last_month/$yes_day/$last_year&quot;         fulldate=&quot;$last_month/$yes_day/$last_year&quot; else         if [$month=&quot;01&quot;] &amp;&amp; [$day=&quot;02&quot;]; then                 date=&quot;$last_month/$yes_day/$last_year&quot;                 fulldate=&quot;$last_month/$yes_day/$last_year&quot;         else                 if [ $day = &quot;01&quot; ]; then                         date=&quot;$last_month/$yes_day/$year&quot;                         fulldate=&quot;$year$last_month$yes_day&quot;                 else                         if [ $day = &quot;02&quot; ]; then                                 date=&quot;$last_month/$yes_day/$year&quot;                                 fulldate=&quot;$year$last_month$yes_day&quot;                         else                                 date=&quot;$month/$yes_day/$year&quot;                                 fulldate=&quot;$year$month$yes_day&quot;                         fi                 fi         fi fi  But my bad am getting the below error message Etime_script.sh: line 19: [06=01]: command not found Etime_script.sh: line 24: [06=01]: command not found
26992
I have this file:  sometext1{ string1 }  sometext2{ string2 string3 }  sometext3{ string4 string5 string6 }   I want to search this file for a specific string and print everything before this string up to the opening { and everything after this string up to the closing }. I tried to achieve this with sed but if I try to print everything in the range /{/,/string2/ for example sed prints this:  sometext1{ string1 }  sometext2{ string2 sometext3{ string4 string5 string6 }   If I search for the string "string2" I need the output to be:   sometext2{ string2 string3 }   Thanks.
43236
I'm attempting to loop through an array of strings, and do something a little different with one of the values.  The string comparison fails on every element.  arr[0]='red' arr[1]='blue' arr[2]='yellow' arr[3]='green'  ## now loop through the above array for i in "${arr[@]}" do         if [ "$i"="green" ];         then                 echo "i('$i') is equal to green"         else                 echo "i('$i') is not equal to green"         fi  done   I've also tried (with the same result):   if [ "$i"='green' ];   and   if [ $i='green' ];   and   if [ $i="green" ];   Output of each of the above:   i('red') is equal to green i('blue') is equal to green i('yellow') is equal to green i('green') is equal to green   What am I doing wrong with the comparison?
113295
I am trying the contents of an array into a file with each element of the array in a new line in the file.  IFS=$'\n'    echo "${mtches[@]}" &gt; sample1.txt     The content of mtches is "qwe" and " asd". But the sample1.txt file contains qwe asd in a single line. Why is it not taking IFS value into the picture?
119464
Suppose I do     grep "MyVariable = False" FormA.frm     ... result1     grep "MyVariable = True"  FormA.frm     ... result2   How to write the grep command so that I can say something like     grep "MyVariable = False" OR "MyVariable = True" FormA.frm
94297
The following bash syntax verifies if param isn't empty:   [[ !  -z  $param  ]]   For example:  param="" [[ !  -z  $param  ]] &amp;&amp; echo "I am not zero"   No output and its fine.  But when param is empty except for one (or more) space characters, then the case is different:  param=" " # one space [[ !  -z  $param  ]] &amp;&amp; echo "I am not zero"   "I am not zero" is output.  How can I change the test to consider variables that contain only space characters as empty?
115440
Simply said, I just can't find a way to match a variable against some pattern containing spaces.  Here is what I expected to work (echo 'ok' string)  item='foobar baz' pat=".+bar baz" if [[ "$item" =~ "$pat" ]] ; then     echo ok fi   Adding/removing quotes around $pat does not seem to make any difference. I get those two erros below:  bash: conditional binary operator expected bash: syntax error near `~='   Could someone please help me pointing out what I am doing wrong here ? Should I put the pattern right away (without any quotes/double quotes, nor variable reference) ? If that is the case, then how can I put spaces in ? (using reg-exp matching, not an alternative)  Thank you !
34780
I want to know which files have the string $Id$.  grep \$Id\$  my_dir/mylist_of_files   returns 0 occurrences.  I discovered that I have to use  grep \$Id$ my_dir/mylist_of_files  Then I see that the $Id is colored in the output, i.e. it has been matched.  How could I match the second $ and why doesn't \$Id\$ work.  It doesn't matter if the second $ is the last character or not.  I use grep 2.9.    Before posting my question, I used google...       To search for a $ (dollar sign) in the file named test2, enter:      grep \\$ test2      The \\ (double backslash) characters are necessary in order   to force the shell to pass a \$ (single backslash, dollar sign) to the   grep command. The \ (single backslash) character tells the grep   command to treat the following character (in this example the $) as a   literal character rather than an expression character. Use the fgrep   command to avoid the necessity of using escape characters such as the   backslash.   but I don't understand why grep \$Id works and why grep \\$Id\\$ doesn't.  I'm a little bit confused...
4793
I want to do:  cat update_via_sed.sh | sed 's/old_name/new_name/' &gt; new_update_via_sed.sh   in my program.  But I want to use variables, e.g.  old_run='old_name_952' new_run='old_name_953'   I have tried using them but the substitution doesn't happen (no error). I have tried:  cat update_via_sed.sh | sed 's/old_run/new_run/' cat update_via_sed.sh | sed 's/$old_run/$new_run/' cat update_via_sed.sh | sed 's/${old_run}/${new_run}/'
65920
I have a input file FILE1.TXT as below.     11 id1   12   13 AGE = 20   14 NAME = NAME1   15   16 id2   17   18 AGE = 30   19 NAME = NAME2   .   .   .   110 idXYZ   111   112 AGE = AGEXYZ   113 NAME = NAMEXYZ   114   115 idZZZ   116     I want to search all the fields that belong to a particular Id and get the value for NAME  I managed to loop through each Id and formed the below command for each Id as required.  sed -n '/11/,/14/p' FILE1.TXT | grep NAME | awk -F "= " '{print $2}'  The problem here is, I get the output NAME1, in addition to that, I also get NAMEXYZ.  What should be changed so that I only get NAME1 but not NAMEXYZ?  As a workaround, the below commands work.  sed -n '/11/,/14/p' FILE1.TXT | grep NAME | awk -F "= " '{print $2}'|head -1  Is there any 'switch' or am I missing something?
84722
I have this if in a bash script:  if [ $ACTION = deploy ]; then     ${JAVA_HOME}/bin/java ${JVM_ARGS} weblogic.WLST &lt;&lt; EOJ     connect('XXX','XXX','t3://XXX:8001')     jndi();     ls();     disconnect();     exit ();     EOJ else     echo "XXX" fi   I think the error is in the EOJ.
53214
I am attempting to write a filter using something like sed or awk to do the following:   If a given pattern does not exist in the input, copy the entire input to the output If the pattern exists in the input, copy only the lines after the first occurrence to the output   This happens to be for a "git clean" filter, but that's probably not important. The important aspect is this needs to be implemented as a filter, because the input is provided on stdin.  I know how to use sed to delete lines up to a pattern, eg. 1,/pattern/d but that deletes the entire input if /pattern/ is not matched anywhere.  I can imagine writing a whole shell script that creates a temporary file, does a grep -q or something, and then decides how to process the input. I'd prefer to do this without messing around creating a temporary file, if possible. This needs to be efficient because git might call it frequently.
39941
I have a question related to deletion of strings that appear at the n+2 position after the matched string which is at position n using awk for multiple files. I am able to print it using the command:   awk -F '/radius-server/{nr[NR+4]}; NR in nr' *   Where the matched string is radius-server.  Since I'm not too familiar with  awk I would appreciate it if someone could help me  delete this line in place , that would mean that I want the files to be modified and saved after the deletion is done.  An example scenario is below - file 1 which is unmodified    radius-server dz7HQQH4EqT5 1645-1646  !  oj5icqh1dGpSK  !    alias exec t telnet  alias exec sis show interface status  !   file 2, after modification is -  radius-server dz7HQQH4EqT5 1645-1646 ! ! alias exec t telnet alias exec sis show interface status !   I understand that I can do a pattern matching method using sed -i '/pattern/d' to remove it but that is not what I want as the values change from file to file. Any help would be much appreciated.
77730
Let's suppose I've declared the following variables:  $ var='$test' $ test="my string"   If I print their contents I see the following:  $ echo $var $test  $ echo $test my string   I'd like to find a way to print the content of the content of $var (which is the content of $test). So I tried to do the following:  $ echo $(echo $var) $test   But here the result is $test and not "my string"... Is it possible to print the content of the content of variables using bash?
37813
I want to split 'hello' into h e l l o in an array using only bash, I could do it in sed with sed 's/./&amp; /g' but I want to know how to split a string into an array in Bash when I do not know what the delimiter would be, or the delimiter is any single character.  I don't think I can use ${i// /} without some creativity because the delimiter is an unknown, and I don't think that expression accepts regex.  I tried using BASH_REMATCH with [[ string =~ ([a-z].).* ]] but it doesn't work as I expected.  What is the proper way to use only bash to accomplish a string.split() type of behavior?  The reason is that I am trying to write the rev utility in all bash:    while read data; do   word=($(echo $data|tr ' ' '_'|sed 's/./&amp; /g'))   new=()   i=$((${#word[@]} - 1))   while [[ $i -ge 0 ]]; do     new+=(${word[$i]})     (( i-- ))   done   echo ${new[@]}|tr -d ' '|tr '_' ' '   done   But I used tr and sed, I want to know how to do the split properly and then I will fix it to be all bash.  Just for fun.
47909
With ksh I'm using read as a convenient way to separate values: $ echo 1 2 3 4 5 | read a b dump $ echo $b $a  2 1 $  But it fails in Bash: $ echo 1 2 3 4 5 | read a b dump $ echo $b $a     $  I didn't find a reason in the man page why it fails, any idea?
29937
I've just encountered several answers such as to  that use the construct:  while IFS=, read xx yy zz;do     echo $xx $yy $zz done &lt; input_file   where the IFS variable is set before the read command.  I've been reading through the  but can't figure out why this is legal.  I tried  $ x="once upon" y="a time" echo $x $y   from the bash command prompt but got nothing echoed. Can someone point me to where that syntax is defined in the reference that allows the IFS variable to be set in that way? Is it a special case or can I do something similar w/ other variables?