Something to keep in mind as you go along is the basic purpose of
xargs (which is so you don't overflow the input buffer of a following command) when your working with a large batch of input (such as what you typically get with
find).
The
sed editor, the streaming editor, works on entire lines either in a file or an input stream (such as files names as in your example).
With
sed, you can "in-line" directives or you can create a file that contains any number of directives (commands to be executed) by
sed in multiple lines to work line by line on the content of a file.
For example, this is a "sed" file that does clean-up of an all upper case and abbreviated file:
Code:
cat 401.sed
s/LOAN BALANCE/Loan Balance/g
s/PIMCO REAL RETURN FUND INST/PIMCO Real Return Fund Institutional/g
s/PIMCO TTL RETURN INSTITUTIONAL/PIMCO Total Return Instutional Fund/g
s/VANGUARD DEV MRKTS INDEX FUND/Vanguard Developed Markets Index Fund/g
s/VANGUARD EXTENDED MKT INX ADMR/Vanguard Extended Market Index Fund Admiral Shares/g
s/VANGUARD INSTITUTIONAL INDEX/Vanguard Institutional Index Fund Institutional Shares/g
s/EMPLOYEE PRE-TAX/CONTRIBUTIONS - EMPLOYEE PRE-TAX/g
s/EMPLOYER MATCH/CONTRIBUTIONS - EMPLOYER MATCH/g
s/ROLLOVER/CONTRIBUTIONS - ROLLOVER/g
s/CONVERSION LOAN FUND/Conversion Loan Fund/g
s/VANGUARD DVLPD MKTS INDEX INST/Vanguard Institutional Developed Markets Index/g
s/VANGUARD EXTENDED MKT IND I CL/Vanguard Extended Market Index Fund Institutional Shares/g
It's used by
Code:
sed -f 401.sed file_name > new_file_name
Another might be
Code:
cat ./src/maps/gnis.sed
/\<SHORT_FORM\>/d;/\<ADM[0-2]\>/p;/\<PPL\>/p;/\<PPLA\>/p;/\<PPLC\>/p;/\<PPLL\>/p
for extracting certain lines from a (really large) file containing geographic names, latitudes and longitudes for placement on a map.
All of the methods described in the above posts are, of course, valid (and some quite inventive, too). But, like many things, simpler can be better -- not always, but frequently. I've pretty much always found it useful to think in terms of making a tool that will be used more than once so I try to keep things as simple as possible with a nod toward efficiency while I'm at it. I'm not being critical here, I'm just sayin'.
Complicated stuff will come back an bite you more often than not and I've tried to avoid those -- plus, half the time I can't remember why in heck I did what I did so I try not to do stuff like that.
For your purpose, renaming files,
xargs and
sed probably are, well, overkill. The best of the bunch up above is the shell substring extraction (
${file%.txt}.bak) -- simple, elegant and efficient.
You know, it's sort of like when all you need is a Phillips screwdriver it doesn't make a heck of lot of sense to drag out the air gun?
Hope this helps some.