linux - Unix - how to use cut -d on one word -


i have string 2 words may contain 1 word , need both words , if second 1 empty want empty string. using following:

string1=`echo $string|cut -d' ' -f1` string2=`echo $string|cut -d' ' -f2` 

when string 1 word both strings equal need second screen empty.

your problem (from cut(1))

`-f field-list' `--fields=field-list'    select printing fields listed in field-list.  fields    separated tab character default.  print line    contains no delimiter character, unless    `--only-delimited' (`-s') option specified.  

you specify -s when extracing second word, or use

echo " $string" | cut -d' ' -f3 

to extract second word (note fake separator in front of $string).


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -