What is use of "cut" command ?Give some examples. Can we use "awk" or "sed" instead of "cut" ? If yes then give some examples?

Showing Answers 1 - 19 of 19 Answers

waheedha

  • Jul 10th, 2006
 

This utility is use to cut out columns from a table or fields from each line of a file.
cut can be used as a filter.

Either the -b, -c, or -f option must be specified.

-b list
The list following -b specifies byte positions (for instance, -b1-72 would pass the first 72 bytes of each line). When -b and -n are used together, list is adjusted so that no multi-byte character is split.


-c list
The list following -c specifies character positions (for instance, -c1-72 would pass the first 72 characters of each line).


-d delim
The character following -d is the field delimiter (-f option only). Default is tab. Space or other characters with special meaning to the shell must be quoted. delim can be a multi-byte character.

  Was this answer useful?  Yes

Cut - Utility used to cut/Strip out the required data/text from the source.

Cut can be used in three modes,

  Stripping by Character

     cut -c 1-3

  STriping by Byte length

       cut -b -1-72

Stripping by delimiter and fields.

     cut -d "|" -f1

where   

-d "|" -> Deleimter used in input text to seperate columns

-f1 -> Field/Column number  

while processing Huge input files, Cut's perfomance is far better than awk

  Was this answer useful?  Yes

Sivaram

  • Jan 2nd, 2007
 

Cut is a powerful command in Unix, Cutting fields we can use the command , for example we would like to extraxct first 3 col

cut -c1-3 sample   (Sample is a file name)

To extract first and 3rd col

cut -d;-f1,-f3 sample

  Was this answer useful?  Yes

cmanne

  • Mar 25th, 2007
 

1. CUT is used to get the specific portion(column) of information from a files separated by a specific charecter(ex: CSV file)

ex: more /etc/passwd|cut -d":" -f1
The above command is used to list the user accounts on the server.
2. AWK
ex: ls -al|awk '{print $9}'
The above command is used to get the list of filenames in the current directory. Here the fields are need not be seperated by a specific charecter.

3. SED is similar to GREP command.

Rahul

  • Mar 28th, 2007
 

The cut command cuts bytes, characters, or fields from each line of a file and writes these bytes, characters, or fields to standard output. If you do not specify the File parameter, the cut command reads standard input.

To display fields using a blank separated list, enter:

            cut -f "1 2 3" -d : /etc/passwd

            The cut command produces:

            su:*:0
            daemon:*:1
            bin:*:2
            sys:*:3
            adm:*:4
            pierre:*:200
            joan:*:202

  Was this answer useful?  Yes

prasul

  • Dec 22nd, 2007
 

SED is a simple editor which will be editing files without a gui and to provide operations on the command line.sed -e s/word1/word2/g filenamehttp://en.wikipedia.org/wiki/SedAWK is a command line argument used for printing out values and arguments.awk '{print $1}';http://en.wikipedia.org/wiki/awk

  Was this answer useful?  Yes

ajit_saley

  • Feb 4th, 2009
 

cut -d":" -f1,3 file
Delimitor ":"
Fields/Columns 1 and 3 are printed.

In this example awk can be used. sed can not be used.

awk can do all the jobs of cut. cut can give o/p byte wise, which is not possible in awk.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions