Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substitutions

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
I want to substitute all the words in my text that end on 'sses' by the word ending on 'ss', so kisses and misses becomes kiss and miss. I wanted to do it with gsub:
{ gsub(/.*sses/,???) }
but I don't think AWK has a memory to remember what's in .*.
Is there any way I can do this with AWK?
 
Here is a an idea for you.

awk ' {
if ($0 ~ /.*sses/) {
str = $0
m = index($0,"s")
val = substr($0,1,m) "s"
gsub(str,val,$0)
}
print
}' file

Awk can do almost anything.
If you run linux look at the alsaconfig script sometime
for an example.
 
Status
Not open for further replies.

Similar threads

Replies
3
Views
139

Part and Inventory Search

Sponsor

Back
Top