tags:

views:

32

answers:

1

hi

I have the following example file

    /etc/sysconfig/network/script.sh = -exe $Builder
    run_installation 123 44 556 4 = run_installation arg1 arg2 arg3 948
    EXE=somthing
    EXE somthing

I have three questions (I write bash script)

  1. how to verify by sed or awk if the string "-exe" exist after "=" character
  2. how to verify by sed or awk if the string run_installation exist in the first of the line (the first word in the line) and after the "=" character as example below (file)

  3. the string EXE in file can be "EXE" or as "EXE=" , how to delete by sed the EXE or EXE=

    I do:

    sed s'/EXE//g' | sed s'/EXE=//g'
    

    but its not nice way to do in my bash script

• I need three different answers!

Lidia

A: 

you did not give further criteria on what to do if conditions 1 and 2 are not found...

awk '/=.*-exe/{f=1;}
/^run_installation.*=.*run_installation/{g=1}
/^EXE/{ gsub(/EXE=|EXE/,"") }
f && g{ print "ok" ;exit }
' file

The above code checks for condition 1 and condition 2 and print "ok" when both are found. The substitution of EXE for condition 3 is added for illustration purpose. State more clearly what you want to do and show your expected output next time

To verify them separately,

awk '/= -exe/{print "found"}' file
awk '/^run_installation.*=.*run_installation/{print "found"}' file
ghostdog74
sorry its should be three answers not all cases on one answer
lidia
can you please edit again as different three answers
lidia
what 3 answers? I don't understand. All your conditions can be done with just 1 awk process. Define and clearly explain what you wish to do, with example input and output samples.
ghostdog74
each answer must be separately , I not want all answers on one awk
lidia
smells like homework.
ghostdog74
another question if run_installation exist as the first string in line but not in the begging of line (space between begging of line to run_installation) then what is the new syntax?
lidia