| General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun! |
| 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. |
|
 |
09-27-2005, 05:31 AM
|
#1
|
|
Member
Registered: Jun 2005
Posts: 41
Rep:
|
Manipulating Fields Of Flat File
Hi all,
I have a flat file and the data in it is having the following format.
4AGDA, 211, 51LN39, 4AGDI, 216, 15, 45ACCUNET Generic Digital Access Local Channels
(Only 1 row is shown).
This as you can see is a comma delimited file. I want to do the follwing manipulation.
Copy the last 4 characters from field1 (ie AGDA)
Copy the last 2 characters from field2 (ie 11)
Copy the last 5 characters from field3 (ie 1LN39)
Copy the last 4 characters from field4 (ie AGDI)
Copy the last 2 characters from field5 (ie 16)
Copy the last character from field6 (ie 5)
Leaving the first 2 characters and copying the rest of the data from field7 (ie 45ACCUNET Generic Digital Access Local Channels)
and then print the result in a new file. This is to be done for all the rows in that falt file.
Please help me with the commands or programming conceptsb to achieve the above functionality.
Thanks and Regards
Prasun
|
|
|
|
09-27-2005, 09:46 PM
|
#2
|
|
Member
Registered: Sep 2005
Posts: 115
Rep:
|
look into sed (stream editor?) or awk (the initials of its creators).
They both manupilate text to do exactly what you need.
|
|
|
|
09-28-2005, 11:09 AM
|
#3
|
|
Member
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34
Rep:
|
there are scripts you can write in C or in shell code that use simple math and for loops to remove just white space, 1 character from the front and so forth
they are 25- 50 lines long, not complicated,
usually for free
search yahoo for , C source code, shell script recipies, shell script file utilities, etc.
|
|
|
|
09-28-2005, 01:26 PM
|
#4
|
|
Moderator
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,088
|
It's not Linux and look suspiciously like homework. Moved to General.
|
|
|
|
09-29-2005, 10:28 AM
|
#5
|
|
LQ Newbie
Registered: Oct 2004
Location: Techsupporthell, WI
Distribution: Ubuntu Feisty Fawn, CentOS 4
Posts: 6
Rep:
|
Another poster has already mentioned sed and awk, so I'll mention perl. Perl is perfectly suited to just this sort of bang together something quickly and manipulate text files.
Try running through this short tutorial: http://www.comp.leeds.ac.uk/Perl/start.html and you should know enough to bash (no pun intended) something together.
Alternatively you could do something with Excel/Calc/Gnumeric as well.
Heck, paypal me $20 and I'll do it for yah. . . unless this is your homework, then you have to do it yourself, yah slacker!
|
|
|
|
09-29-2005, 10:34 AM
|
#6
|
|
Member
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34
Rep:
|
perl is good because it works on a shell, in UNIX anyway.
its a good utility language,
its a nice thing to learn
**pay attention to how you make calls to system resources,
be carefull with regular expressions
dont let a perl script run by itself as root when used on the Web....
do some research
|
|
|
|
09-29-2005, 10:37 AM
|
#7
|
|
Member
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34
Rep:
|
hey phishtrader,
what are you phishing for??
and are you trading it??
gee, are you a kiddie??
a cracker that calls himself a hacker??
i may be misunderstanding whats behind that screenname, but i dont think i am
|
|
|
|
09-29-2005, 11:05 AM
|
#8
|
|
LQ Newbie
Registered: Oct 2004
Location: Techsupporthell, WI
Distribution: Ubuntu Feisty Fawn, CentOS 4
Posts: 6
Rep:
|
Quote:
Originally posted by bunnyrage
hey phishtrader,
what are you phishing for??
and are you trading it??
gee, are you a kiddie??
a cracker that calls himself a hacker??
i may be misunderstanding whats behind that screenname, but i dont think i am
|
I'm not phishing for anything. But, I do like to go fishing, particularly for trout, walleye, northern pike, perch, white bass, and crappies.
I don't trade fish, but I do trade live Phish recordings as well as recordings of other jambands. In the past, I did this mostly through my ftp server and BnPs, although these days I'm using bittorrent as it is a much more efficient use of my time. All done legally, as Phish allows the trading of their audience recordings.
Not a kiddie, not a cracker (but I am caucasian), and my last hack was building a low impedence microphone to use with a harmonica and a guitar amp for less than $12 in parts from a local electronics shop.
Yes, I think you're misunderstand what's behind my screenname.
|
|
|
|
09-29-2005, 11:25 AM
|
#9
|
|
Member
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34
Rep:
|
yes i guess i did,
im glad i did,
carefull though, i was easy to lead me to think other things
phish, the band, that wasnt my first thought.
it sounds as though you phish for info and sell it.
but hey the hack is nice!
yeah i agree, your not a script kiddie,
you seem to be a hacker in the traditional sense.
thats always encouraging.
i stand corrected.
no insults
|
|
|
|
09-29-2005, 11:41 AM
|
#10
|
|
LQ Newbie
Registered: Oct 2004
Location: Techsupporthell, WI
Distribution: Ubuntu Feisty Fawn, CentOS 4
Posts: 6
Rep:
|
Quote:
Originally posted by bunnyrage
phish, the band, that wasnt my first thought.
it sounds as though you phish for info and sell it.
|
Phish the band predates the term "phishing," but yes, potentially confusing for some. I like to live on the edge!
|
|
|
|
09-29-2005, 11:42 AM
|
#11
|
|
Member
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34
Rep:
|
HHAHHAHAHHA
|
|
|
|
| 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 02:16 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
|
|