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/tr find and replace on multiple files

Status
Not open for further replies.

dbluch

Technical User
Jan 8, 2003
1
US
Is there a way to perform a character translation on multiple files?

Something similar to a mv *.txt /TextFiles/. which moves all .txt files to the new dir.

If I do a tr -s ' ' '_' < *.txt (which I want to replace all spaces with underscores in all .txt files), I get a shell error.

Maybe with awk?
nawk '/ / {gsub(&quot; &quot;,&quot;_&quot;);print}' *.txt
But this just spits it out to the userspace. An IO redirect results in another shell error.

thanks
Dean
 
#!/bin/ksh

for i in *.txt
do
ex - ${i} <<EOF
%s/ /_/g
wq!
EOF
done
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Or if you want to use awk and create a copy of the files in another directory

nawk '{gsub(/ /,&quot;_&quot;);fn=&quot;/TextFiles/&quot; FILENAME;print > fn}' *.txt

CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top