Click here for important information about

Solved Korn shell Cut Command With Braces

April 5, 2013 at 07:01:16
Specs: Windows 7
I'm trying to access the data to the right of the colon but I am unable to. When I try to display it I get a blank response. Can anyone tell how to get around the braces so I can access the date and display it or use it for a condition statement? I appreciate any help. Thanks in advance!

command response:

“DATE1” : 000,
“DATE2” : 111,
“DATE3” : 222

my code:
while [[ $i -ne 4 ]] ; do
T=data|cut -d':' -f2
echo $i is $T

See More: Korn shell Cut Command With Braces

April 5, 2013 at 07:35:35
✔ Best Answer
I don't think cut is thie best tool. How about awk. I am assuming you do not want the commas. Let me know if you have any questions:


# use awk if you are NOT using Solaris
nawk ' BEGIN { FS=":" }
if(NF > 1)
   gsub(",", "") # delete comma
   gsub(" ","") # gett rid of leading space
   print $NF # print last field

} ' data.txt

Here is another way parsing with the shell:

while IFS=":" read first therest
   if [ ! -z $therest ]
   then # print only if defined
      therest=$(echo $therest| tr -d ',')
      echo $therest
done < data.txt

Report •
Related Solutions

Ask Question