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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk to find spaces and replace with tabs

Status
Not open for further replies.

missingbrain

Technical User
Mar 15, 2003
2
US
I have searched high and low to find a working example of how you can use awk to search for each space in a file and replace it with a tab.

E.g. input: I<sp>can't<sp>use<sp>awk<sp>very<sp>well.
output: I<tab>can't<tab>use<tab>awk<tab>very<tab>well.

Doesn't seem to difficult, but when I use \t for the tab as a replacement, awk seems to always error out.

I am looking to read in input from input.txt and send the output to output.txt

Thanks in advance.
 
Hi:

nawk ' {
sub(&quot; &quot;, &quot;\t&quot;, $0)
print $0
}
' space.file > tab.file

I use nawk under Solaris 7. Also, see:

thread271-500232

Regards,

Ed
 
Ed,

Much obliged. For the redhat install I am using, I couldn't use nawk, but awk with the same context worked great.

Thanks

Ryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top