LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
LinkBack Search this Thread
Old 05-25-2004, 08:14 AM   #1
pantera
Member
 
Registered: May 2004
Posts: 80

Rep: Reputation: 15
seperating values using perl


how to separate fields of a file:

ABCD 0.000 1.000 2.000 3.000 4.000 5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 24.000
100 - - VALUES - - - DATAS - - - - ANGLE - - -
101 THETA (DEGREES) 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 24.000 25.000 26.000 27.000 28.000 29.000 30.000 31.000 32.000 33.000 34.000 35.000 36.000 37.000 38.000 39.000

how can i sort/modify the above values just to get the numerical values
 
Old 05-25-2004, 12:10 PM   #2
jmcgarey
LQ Newbie
 
Registered: Mar 2004
Distribution: Mandrake and Mepis
Posts: 9

Rep: Reputation: 0
Some ideas

Heres some quick tries at getting to your goal but they are not in PERL.

If you are speaking of doing this task in a PERL script then these may be of no use at all. If you are speaking of command line they could potentially be useful. If you need this done only PERL let us know. Perhaps are you trying to get them into a perl list?

Like I said this is just a starting point. they are not perfect but they could serve to show what kind of output you want. Try them on a command line and reply with specifics about how the output should be changed. The file you speak of is assumed to be named 'file' in the current directory.

Code:
awk '/[0-9]*\./ { for (col = 1; col <= NF; col++) printf"%3s\n", $col; printf"\n\n"}' fasss | grep '[0-9]\.'
Code:
grep -i '[0-9]\.' file | sed -e 's/[a-zA-Z\\(\)]//g'
This one could be a winner:
Code:
grep -i '[0-9]\.' fasss | sed -e 's/[a-zA-Z\\(\)]//g' | sed -e 's/[0-9]*\..*/&/' | sed -e 's/[0-9]* //'


This one is the least directly useful but I came up with it and it can be used for hints on how this stuff works. it could be extended out to list them all one by one.
Code:
awk '/[0-9]*\./ { printf"%3s", ($1); printf"  %3s", ($2); printf"\n"}'  file

Let us know if you have any questions.
 
Old 05-25-2004, 12:33 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 58
What is your file seperator - use a regex in place of "REGEX":
@fields=split(/REGEX/,$string);
 
Old 05-26-2004, 12:31 AM   #4
pantera
Member
 
Registered: May 2004
Posts: 80

Original Poster
Rep: Reputation: 15
using only perl

thanx for the help ......it is working fine using grep but i need something that uses only perl...no grep or awk
thanx
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lua - seperating a string blackman890 Programming 13 03-28-2005 10:04 AM
Seperating IPTABLES Logs TheRealDeal Linux - Security 5 02-26-2005 08:51 AM
rx/tx values Nauseous *BSD 1 05-26-2004 02:06 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
Perl of Wisdom needed for reading in iptables values pjcp64 Programming 5 06-02-2003 05:52 AM


All times are GMT -5. The time now is 03:53 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
Open Source Consulting | Domain Registration