LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Reply
 
Search this Thread
Old 09-27-2005, 05:31 AM   #1
Prasun1
Member
 
Registered: Jun 2005
Posts: 41

Rep: Reputation: 15
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
 
Old 09-27-2005, 09:46 PM   #2
debianmike
Member
 
Registered: Sep 2005
Posts: 115

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

They both manupilate text to do exactly what you need.
 
Old 09-28-2005, 11:09 AM   #3
bunnyrage
Member
 
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34

Rep: Reputation: 15
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.
 
Old 09-28-2005, 01:26 PM   #4
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,176
Blog Entries: 4

Rep: Reputation: 430Reputation: 430Reputation: 430Reputation: 430Reputation: 430
It's not Linux and look suspiciously like homework. Moved to General.
 
Old 09-29-2005, 10:28 AM   #5
phishtrader
LQ Newbie
 
Registered: Oct 2004
Location: Techsupporthell, WI
Distribution: Ubuntu Feisty Fawn, CentOS 4
Posts: 6

Rep: Reputation: 0
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!
 
Old 09-29-2005, 10:34 AM   #6
bunnyrage
Member
 
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34

Rep: Reputation: 15
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
 
Old 09-29-2005, 10:37 AM   #7
bunnyrage
Member
 
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34

Rep: Reputation: 15
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
 
Old 09-29-2005, 11:05 AM   #8
phishtrader
LQ Newbie
 
Registered: Oct 2004
Location: Techsupporthell, WI
Distribution: Ubuntu Feisty Fawn, CentOS 4
Posts: 6

Rep: Reputation: 0
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.
 
Old 09-29-2005, 11:25 AM   #9
bunnyrage
Member
 
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34

Rep: Reputation: 15
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
 
Old 09-29-2005, 11:41 AM   #10
phishtrader
LQ Newbie
 
Registered: Oct 2004
Location: Techsupporthell, WI
Distribution: Ubuntu Feisty Fawn, CentOS 4
Posts: 6

Rep: Reputation: 0
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!
 
Old 09-29-2005, 11:42 AM   #11
bunnyrage
Member
 
Registered: Sep 2005
Distribution: Fedora Core 2
Posts: 34

Rep: Reputation: 15
HHAHHAHAHHA
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
permissions on flat file php authentication blizunt7 Linux - Security 2 11-23-2005 06:13 AM
Delete line from flat text file in C zaichik Programming 6 01-26-2005 06:16 PM
Making VSAM file from a flat file in AIX Raghothaman AIX 2 08-25-2004 04:55 PM
Displaying fields in wtmp file? eclapton1 Programming 1 06-26-2004 09:51 PM
Flat File QC Scripting mychl Programming 5 02-20-2004 11:53 AM


All times are GMT -5. The time now is 01:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration