Computing.Net > Forums > Unix > finding length of a field in shell

finding length of a field in shell

Reply to Message Icon

Original Message
Name: roopa_arjunan
Date: August 3, 2005 at 00:47:50 Pacific
Subject: finding length of a field in shell
OS: unix
CPU/Ram: unknown
Comment:

hi,
how to find whether a field is empty
for eg:
this|is|on| |line| |

in this how to find the length of fourth field.

thank you.

Roopa.A


Report Offensive Message For Removal


Response Number 1
Name: David Perry
Date: August 3, 2005 at 05:44:48 Pacific
Subject: finding length of a field in shell
Reply: (edit)

echo "this|is|on| |line| |" | awk -F"|" '{ print length($4)}'


Report Offensive Follow Up For Removal

Response Number 2
Name: Jim Boothe
Date: August 3, 2005 at 06:54:11 Pacific
Subject: finding length of a field in shell
Reply: (edit)

And just for variety:

echo "this|is|on| |line| |" |
  IFS=\| read f1 f2 f3 f4 rem

echo "length of field 4: ${#f4}"

1


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: finding length of a field in shell

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software