Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Cut command - problems

3 posters

Go down

Cut command - problems Empty Cut command - problems

Post by Maithreyi Wed Mar 03, 2010 4:26 pm

I have a file abc with contents :

1🔤25
2:pqr:30
3:rst:12

Now, suppose I give cut -d : -f 1 abc -> we get
1
2
3

But, if we have multiple fields in the above command the delimiter is still present.Isn't cut supposed to strip by delimiter ? Will the delimiter between column 1 and 2 be present in the output as well ?

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

Cut command - problems Empty pls be still clear

Post by mightyganesh Wed Mar 03, 2010 4:32 pm

i just cant understand your question completely.

are you asking that why does the command
Code:
cut -d : -f1,2 abc

produces output like

Code:
1:abc
2:pqr
3:rst

or some things else??? confused
mightyganesh
mightyganesh

Posts : 53
Points : 92
Join date : 2010-02-26
Age : 35

http://ganeshguna.blogspot.com

Back to top Go down

Cut command - problems Empty Re: Cut command - problems

Post by Christopher Wed Mar 03, 2010 4:34 pm

Yes. The ":" will be there in the output to separate the columns.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Cut command - problems Empty Re: Cut command - problems

Post by Maithreyi Wed Mar 03, 2010 4:35 pm

@mightyganesh that was what I was asking!
@Christopher Thanks!

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

Cut command - problems Empty Re: Cut command - problems

Post by mightyganesh Wed Mar 03, 2010 4:47 pm

good! it will contain : in the output

do u wanna know how to remove that delimiter from the output ??

then try
Code:
 cat /etc/passwd | cut -d ':' -f1,2,3 | tr ':' '\0'

this will remove the delimiter produced by the code
Code:
cat /etc/passwd | cut -d ':' -f1,2,3
mightyganesh
mightyganesh

Posts : 53
Points : 92
Join date : 2010-02-26
Age : 35

http://ganeshguna.blogspot.com

Back to top Go down

Cut command - problems Empty Re: Cut command - problems

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum