Solved

Need help reading ksh script

Posted on 2013-06-10
5
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
edit multiple files in several directories with the same text in Linux 6 74
Strange html entity encoding by tidy 14 100
FTP Script 25 61
while read ID; do 4 54
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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