Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to delete words starting with x from a text file in unix.
e.g: xaa, xab ...
Please help me

This awk script looks at each field and if the field starts with x and is composed of characters and numbers, then set to the field to a space:
I am using Solaris nawk.
nawk ' {for(i=1; i<=NF; i++)
gsub("^x[0-9A-Za-z]*$", "", $i)
print $0} ' datafile

are the words on their own line or at the beginning of a line, or can they appear anywhere in the file?

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |