Computing.Net > Forums > Unix > please help me with awk, please

please help me with awk, please

Reply to Message Icon

Original Message
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



Report Offensive Message For Removal


Response Number 1
Name: LANkrypt0
Date: September 16, 2002 at 11:19:22 Pacific
Subject: please help me with awk, please
Reply: (edit)

Try this one it worked just fine for me.

sed -e 's/^\$.* --/$+ --/g' filename


Report Offensive Follow Up For Removal

Response Number 2
Name: 4el
Date: September 17, 2002 at 00:04:16 Pacific
Subject: please help me with awk, please
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 3
Name: James Boothe
Date: September 17, 2002 at 06:48:19 Pacific
Subject: please help me with awk, please
Reply: (edit)

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.

sed -e 's$[^ ]*/$+/g' filename


Report Offensive Follow Up For Removal

Response Number 4
Name: LANkrypt0
Date: September 17, 2002 at 07:38:40 Pacific
Subject: please help me with awk, please
Reply: (edit)

Longer one line sed'er. But this one worked for me. Probably an easier way, but this should do the trick:

sed -e "s/ -- /XxXxSx/g" -e "s/ - /XxXxPx/g" -e 's/^\$.*XxXx/$+/g' -e "s/+Sx/+ -- /g" -e "s/+Px/+ - /g" datafile


Report Offensive Follow Up For Removal

Response Number 5
Name: LANkrypt0
Date: September 17, 2002 at 07:40:42 Pacific
Subject: please help me with awk, please
Reply: (edit)

Thanks for the easier way James :)


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: please help me with awk, please

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software