LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (http://www.linuxquestions.org/questions/general-10/)
-   -   Manipulating Fields Of Flat File (http://www.linuxquestions.org/questions/general-10/manipulating-fields-of-flat-file-367430/)

Prasun1 09-27-2005 06:31 AM

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

debianmike 09-27-2005 10:46 PM

look into sed (stream editor?) or awk (the initials of its creators).

They both manupilate text to do exactly what you need.

bunnyrage 09-28-2005 12:09 PM

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.

XavierP 09-28-2005 02:26 PM

It's not Linux and look suspiciously like homework. Moved to General.

phishtrader 09-29-2005 11:28 AM

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!

bunnyrage 09-29-2005 11:34 AM

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

bunnyrage 09-29-2005 11:37 AM

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

phishtrader 09-29-2005 12:05 PM

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.

bunnyrage 09-29-2005 12:25 PM

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

phishtrader 09-29-2005 12:41 PM

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!

bunnyrage 09-29-2005 12:42 PM

HHAHHAHAHHA


All times are GMT -5. The time now is 12:03 PM.