Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-07-2010, 05:35 AM
|
#1
|
Member
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132
Rep:
|
awk problem
i did the following script
Code:
echo Every good boy is bad boy | awk '{first=substr($0,1,2)}{second=substr($0,8)}{printf("%s%s\n",first,second)}'
The result is Evood boy is bad boy
How to get the following result
Evood boy is baoy (substr the d,<space> and b)
when i try this
Code:
echo Every good boy is bad boy| awk '{first=substr($0,1,2)}{second=substr($0,8)}{third=substr($5,1,2)}{fourth=substr($6,2)}{printf("%s%s%s%s\n",first,second,third,fourth)}'
im getting this
Evood boy is bad boybaoy
Please advice
Thanks
Jo
|
|
|
01-07-2010, 07:43 AM
|
#2
|
LQ Newbie
Registered: May 2009
Distribution: Slackware
Posts: 17
Rep:
|
This works, (if not then it's a cut and paste problem from my side).
Code:
echo Every good boy is bad boy | awk '{first=substr($0,1,2);second=substr($0,7,4);third=substr($0,11,10);fourth=substr($0,24,2);}END{printf("%s%s%s%s\n",first,second,third,fourth)}'
The first 'substr' function returns 2 chars from string, starting at position 0, just to be clear, 'substr' doesn't delete chars from the string. To get what you want you have to extract and concatenate the desired chars from the strings.
|
|
|
All times are GMT -5. The time now is 08:50 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|