user1701840
user1701840

Reputation: 1112

how to use cut to manipulate string in ksh?

I know how to use cut in a text file or in pipe line. But when it comes to using cut in ksh, I am having some difficulty dealing with it.

#!/bin/ksh
...
result=$(cut -d: -f1 string)  //assume string = "first:second:third"
print $result                 //I want to print out "first"

when I do this I got my stdout saying that cut cannot open string. Which I kind of know why because cut is for file. What should I do to archieve my goal?

Upvotes: 1

Views: 8281

Answers (1)

user529758
user529758

Reputation:

result=$(echo $string | cut -d: -f1)

Upvotes: 1

Related Questions