[PLUG] File content modification

शंतनू (Shantanoo) shantanoo at gmail.com
Tue Aug 3 00:19:05 IST 2010


On Sat, Jul 31, 2010 at 12:32, Shreerang Patwardhan
<patwardhan.shreerang at gmail.com> wrote:
> Hello all,
>     I have a file with contents in the following manner:
> 10001_abc_county
> 10003_abc_xyz_county
> 10005_abc_pqr_xyz_county
>
> Each entry is on a new line and each line begins with a number and ends with
> the word county!
>
> I wish to convert the contents of this file in the form as specified below:
> abc
> abcxyz
> abcpqrxyz
>
> How do I get around this?
> Need help!
>

One liners:

Partial solution (you can try the minor change and get the complete solution):
cat <file> | perl -e 'for(<>) { s/^[0-9]+_(.*)_[a-z]+$/$1/g;print}'

Complete:
python -c 'for x in open("<file>","r").readlines(): print
"".join(x.split("_")[1:-1])'




More information about the Plug-mail mailing list