• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Need help reading ksh script

Can someone tell me what does this line do?

cut -d"/" -f1-4`

I understand that it grabs the string, ignored the forward slash character and cus characters 1 throught 4 from the string. Am I correct?

Also what is the difference when cut command is called with -c1-4 as opposed to -f1-4?
  • 2
  • 2
2 Solutions
man cut
     -c list
             The list specifies character positions.

     -d delim
             Use delim as the field delimiter character instead of the tab character.

     -f list
             The list specifies fields, separated in the input by the field delimiter character (see the -d option.)  Output fields are separated by a single occurrence of the field delimiter

cut -d"/" -f1-4
prints everything up to   the 4th / on each line
YZlatAuthor Commented:
but what does it do to the / character?
It uses it as a field delimiter to determine what the first 4 fields are
YZlatAuthor Commented:
But what about the difference bewteen -f1-4 and -c1-4?
nemws1Database AdministratorCommented:
If we have this string as input:


And we run this

cut -d"/" -f1-4

The output is:


If we run this:

cut -d"/" -c1-4

We get an error.  Specifying *both* -d and -c doesn't make sense, as '-c' already uses a null character as a delimiter (meaning the thing between each individual character, which is actually nothing).  We can do this however:

cut -c1-4

And with our input, we'll get:


(I perhaps should have chosen a better string!)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now