INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

how to substr a string ?

how to substr a string ?

(OP)
Dear ALL,
I want to extract a string from a file and using the substr function to extract substrings from a string.

I have a file name say "test.dat"
 cat test.dat | awk '{if($1=="Latitude")  print $6 }'

this produce say "-090206.48241"

the I pipe this directly to

 cat test.dat | awk '{if($1=="Latitude")  print $6 }' | awk '{ printf("%3i %1i %8.5f\n"),substr($0,1,3),substr($0,4,5),substr($0,5,10)}'

What I wanted this to produce is to extract and output as:
-09  02  06.48241.

The above awk did not do just that ?

Any comments please

Yacob Sen

 

RE: how to substr a string ?

(OP)
Errata to the question
sorry I meant

 cat test.dat | awk '{if($1=="Latitude")  print $6 }' | awk '{ printf("%3i %2i %8.5f\n"),substr($0,1,3),substr($0,4,2),substr($0,6,5)}'

it produces: 9  2  6.48000

This misses the "-" and as well as the zeros. I wanted it to produce:
-09  02  06.48000

Regards
Yacob

RE: how to substr a string ?

(OP)
Dea PHV

It worked as I would like it to be. Thank you so much !!
Thank You

Regards
Yacob

 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close