Yo; I have a series of comma-delimited text files with fourteen columns of data and several hundred rows. I want to use a short shell script to strip them of the last 9 columns, leaving the same file but with just five of its columns. I can do it in C++, but that seems like overkill. How would I go about doing it with sed or a similar utility? SigmaX
On Tue, Sep 19, 2006 at 12:26:54PM -0400, SigmaX asdf wrote:> Yo; > > I have a series of comma-delimited text files with fourteen columns of > data and several hundred rows. I want to use a short shell script to > strip them of the last 9 columns, leaving the same file but with just > five of its columns. I can do it in C++, but that seems like > overkill. How would I go about doing it with sed or a similar > utility?See cut(1): cut -d, -f1,2,3,4,5 -- Brooks -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 187 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/freebsd-stable/attachments/20060919/1cbf9ea2/attachment.pgp
* SigmaX asdf <fydernix@gmail.com> [20060919 18:31]:> I have a series of comma-delimited text files with fourteen columns of > data and several hundred rows. I want to use a short shell script to > strip them of the last 9 columns, leaving the same file but with just > five of its columns. I can do it in C++, but that seems like > overkill. How would I go about doing it with sed or a similar > utility?cut -d ',' -f 1-5 qvb -- pica
On Tue 19 Sep 12:26, SigmaX asdf wrote:> I have a series of comma-delimited text files with fourteen columns of > data and several hundred rows. I want to use a short shell script to > strip them of the last 9 columns, leaving the same file but with just > five of its columns. I can do it in C++, but that seems like > overkill. How would I go about doing it with sed or a similar > utility?cut -d, -f 1-5 Cheers, Nick. -- "You call _that_ a knife? _This_ is what _I_ call a knife!" "Really? No worries. _This_ is what I call a crossbow!"
Reference:> From: "SigmaX asdf" <fydernix@gmail.com> > Date: Tue, 19 Sep 2006 12:26:54 -0400 > Message-id: <c04d7e300609190926t1e5dce14wea7ef1a16ccf9af1@mail.gmail.com>"SigmaX asdf" wrote:> Yo; > > I have a series of comma-delimited text files with fourteen columns of > data and several hundred rows. I want to use a short shell script to > strip them of the last 9 columns, leaving the same file but with just > five of its columns. I can do it in C++, but that seems like > overkill. How would I go about doing it with sed or a similar > utility?awk ! /usr/ports/lang/gawk exists too. PS Here's odd notes from my syntax file, not exactly appropriate to you, but near enough to give ideas with `man awk' for ref, & `fun' to learn ;-) ---- awk '{printf "rm -f %s ; ln -s ..%s %s\n",$1,$3,$1}' < /tmp/x awk -F = '{printf "%s\n",$1}' < /tmp/t awk --field-separator # '{printf "%s\n",$1}' awk -F # '{printf "%s\n",$1}' # 5.0 has no --field-separator awk '{printf "%s\n",$1}' < distfiles.dump find /etc /var /usr -type l | sort | xargs ls -l | \ awk '{printf "%s -> %s\n",$9,$11}' # List all links -- Julian Stacey. BSD Unix C Net Consultancy, Munich/Muenchen http://berklix.com Mail Ascii, not HTML. Ihr Rauch = mein allergischer Kopfschmerz. Don't buy it ! Get it free ! http://berklix.org/free-software
SigmaX asdf wrote:> Yo; > > I have a series of comma-delimited text files with fourteen columns of > data and several hundred rows. I want to use a short shell script to > strip them of the last 9 columns, leaving the same file but with just > five of its columns. I can do it in C++, but that seems like > overkill. How would I go about doing it with sed or a similar > utility? > > SigmaXAll of advices were cool but! there's a good idea to work around something like that, but I don't exactly know now how to solve your problem, the idea is: `perl -pi~ -e 's/foo/bar/g' somefile` works fine for `somefile'... I think TIMTOWTDI. -- Oleg D. -- don't believe every word people use to say, they might be wrong. an undefined problem has infinitive number of solutions. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3233 bytes Desc: S/MIME Cryptographic Signature Url : http://lists.freebsd.org/pipermail/freebsd-stable/attachments/20060919/a3a5c5d0/smime.bin
On Tue, September 19, 2006 9:26 am, SigmaX asdf wrote:> I have a series of comma-delimited text files with fourteen columns > of data and several hundred rows. I want to use a short shell script > to strip them of the last 9 columns, leaving the same file but with > just five of its columns. I can do it in C++, but that seems like > overkill. How would I go about doing it with sed or a similar > utility?cat file | awk -F"," '{ printf "%s,%s,%s,%s,%s\n",$1,$2,$3,$4,$5 }' > newfile You can probably even remove the cat and just use awk on the file directly. ---- Freddie Cash fcash@ocis.net