Solved

Need help reading ksh script

Posted on 2013-06-10
5
155 Views
Last Modified: 2013-06-11
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?
0
Comment
Question by:YZlat
  • 2
  • 2
5 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 39235078
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
             character.

so
     
cut -d"/" -f1-4
prints everything up to   the 4th / on each line
0
 
LVL 35

Author Comment

by:YZlat
ID: 39235094
but what does it do to the / character?
0
 
LVL 84

Expert Comment

by:ozo
ID: 39235119
It uses it as a field delimiter to determine what the first 4 fields are
0
 
LVL 35

Author Comment

by:YZlat
ID: 39235132
But what about the difference bewteen -f1-4 and -c1-4?
0
 
LVL 23

Assisted Solution

by:nemws1
nemws1 earned 250 total points
ID: 39235183
If we have this string as input:

Hello/there/my/friend/how/are/you/?

And we run this

cut -d"/" -f1-4

The output is:

Hello/there/my/friend

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:

Hell

(I perhaps should have chosen a better string!)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now