Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| 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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-12-2009, 11:52 AM
|
#1
|
|
Member
Registered: Jul 2009
Location: Buenos Aires, Argentina
Distribution: fedora, slackware, *bsd
Posts: 42
Rep:
|
translating text with awk or sed
Hi all,
I would like to know how can I parse a line like this:
IT©Author«what is CP/M?*an OS
into something like:
Category: IT
Question: what is CP/M?
Answer: an OS
Author: Author
I have to parse a file with 60000 lines like that.
Do you know how can I make an awk syntax to accomplish this task?
Thanks in advance!
|
|
|
|
11-12-2009, 12:52 PM
|
#2
|
|
Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,594
|
Quote:
Originally Posted by mek
Do you know how can I make an awk syntax to accomplish this task?
|
Yes, I do know how to accomplish this task. But, why not take a stab at it yourself first. At least try.
Try:
http://www.grymoire.com/Unix/Awk.html
|
|
|
|
11-12-2009, 01:29 PM
|
#3
|
|
Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,594
|
Ok, here I'll give you a hint as to how I might do it:
Code:
awk '{ printf("Category: %s", substr($1,1,index($1,"©")-2)); }' test
Note that some trouble may come from the strange characters that are used.
|
|
|
|
11-12-2009, 01:40 PM
|
#4
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
Why not first parse the file to get rid of all the strange characters?---then awk can just work on fields normally.
|
|
|
|
11-12-2009, 06:32 PM
|
#5
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
Code:
# awk -vFS='\302\251|\302\253|*' '{print $1,$2,$3,$4}' file
IT Author what is CP/M? an OS
do the rest yourself.
|
|
|
|
11-13-2009, 07:57 AM
|
#6
|
|
Member
Registered: Jul 2009
Location: Buenos Aires, Argentina
Distribution: fedora, slackware, *bsd
Posts: 42
Original Poster
Rep:
|
Thanks guys, I sorted out the issue working with sed to replace all those weird character with commas and then I used cut to extract the text to different files.
Thanks for your tips in awk anyway, I'll play arround that
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:51 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
|
|