|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
Let's say I have a text file look like this: 1,0,1,1,0 0,1,1,0,0 1,1,1,0,0 1,0,0,1,1 I just wanna delete first 4 columns(leave 5-9 columns) to get: 1,1,0 1,0,0 1,0,0 0,1,1 Which command should I choose? colrm/tr/sed/awk/cut? It seems that sed/awk take that file as a four row one column file. And I can't use cut -c5-9 <infile> > <outfile>, since the real problem involves other issue. Thanks a lot!! -S |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2006-12-04, CU.CISL@gmail.com wrote:
> Hi, > > Let's say I have a text file look like this: > > 1,0,1,1,0 > 0,1,1,0,0 > 1,1,1,0,0 > 1,0,0,1,1 > > I just wanna delete first 4 columns(leave 5-9 columns) to get: > > 1,1,0 > 1,0,0 > 1,0,0 > 0,1,1 > > Which command should I choose? colrm/tr/sed/awk/cut? It seems that > sed/awk take that file as a four row one column file. And I can't use > cut -c5-9 <infile> > <outfile>, since the real problem involves other > issue. What issue is that? What's wrong with cut -c5-9? Or: cut -c5- Or: cut -d, -f3- -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
CU.CISL@gmail.com wrote:
> Hi, > > Let's say I have a text file look like this: > > 1,0,1,1,0 > 0,1,1,0,0 > 1,1,1,0,0 > 1,0,0,1,1 > > I just wanna delete first 4 columns(leave 5-9 columns) to get: > > 1,1,0 > 1,0,0 > 1,0,0 > 0,1,1 > > Which command should I choose? colrm/tr/sed/awk/cut? It seems that > sed/awk take that file as a four row one column file. And I can't use > cut -c5-9 <infile> > <outfile>, since the real problem involves other > issue. > > Thanks a lot!! > -S > Eihter of these may do what you want: awk 'BEGIN{FS=OFS=","}{print $3,$4,$5}' file sed 's/....//' file cut -d, -f3-5 It's hard to say given there's some unspecified "other issue"... Regards, Ed. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Thanks Ed and Chris! That me a lot!
Ed Morton wrote: > CU.CISL@gmail.com wrote: > > > Hi, > > > > Let's say I have a text file look like this: > > > > 1,0,1,1,0 > > 0,1,1,0,0 > > 1,1,1,0,0 > > 1,0,0,1,1 > > > > I just wanna delete first 4 columns(leave 5-9 columns) to get: > > > > 1,1,0 > > 1,0,0 > > 1,0,0 > > 0,1,1 > > > > Which command should I choose? colrm/tr/sed/awk/cut? It seems that > > sed/awk take that file as a four row one column file. And I can't use > > cut -c5-9 <infile> > <outfile>, since the real problem involves other > > issue. > > > > Thanks a lot!! > > -S > > > > Eihter of these may do what you want: > > awk 'BEGIN{FS=OFS=","}{print $3,$4,$5}' file > sed 's/....//' file > cut -d, -f3-5 > > It's hard to say given there's some unspecified "other issue"... > > Regards, > > Ed. |
|
![]() |
| Outils de la discussion | |
|
|