Name: 4el Date: September 16, 2002 at 08:44:01 Pacific Subject: please help me with awk, please OS: Linux CPU/Ram: Intel
Comment:
I have a txt file with description of many different variables, smt like: "....... $Start_engine -- starting engine $Kill_process -- kills a process $Find_Gates_and_kill_him -- search for a windows pc ....... "
and so on, one thing, that i need to do, is to change all variables into "$+", before $Start_engine -- starting engine need to be $+ -- starting engine
I break my mind with awk and sed, but I cannot find, how I can do it:( the problem is this f**** $-symbol, that him (awk) interprets as variable. if u know, please help, and I will try to help u:) bit thanks
hmm, sorry are u sure? it doesn't work here:( one problem is, that is not always an "--" after variable, it can be smt like this -> \"$equiv\" or -> \"$user\" on $HOST or -> /usr/sap/$SID on Super_Brain
how can i say to sed, take from "$" until space, and not until "--"? thx
The solution posted by LANkrypt0 works fine for me on the sample data in your original post, but that turns out to be more restrictive than you need. That solution changes only strings that begin the line with $ and terminate with space-dash-dash.
But you also want it to change:
/usr/sap/$SID on Super_Brain
The following gets sort of close:
sed -e 's/\$.* /$+ /g' filename
The beginning-of-line anchor (carat) was taken out so that it will search entire line. It looks for a string starting with $ followed by any number of characters and terminated with a space. But that finds the largest qualifying string. Instead of stopping at the first space, it will stop at the last space.
The following works for me, which searches entire line for a string beginning with $ followed by any number of non-spaces. You might have to precede the $ with a backslash, although not required for my shell.