LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 03-18-2005, 06:26 AM   #1
rohr
Member
 
Registered: Jan 2005
Distribution: debian
Posts: 44

Rep: Reputation: 15
line numbering in ASCII file


Hi,
i have a very simple problem to solve for analyzing ASCII data file.

My files are obtained as output of awk processing and look this:
Code:
average: 4.216
average: 9.33867
average: 10.53893
 ...
 ...
they have a certain number of lines (say 10) and only two columns, one with "average:" and the other with "number".
Well, i have to plot the numbers in the second column with respect to another set of values to insert in a column before the second, and then i have to draw one column with respect to the other (i already know how to do this using gnuplot).
They'd look like this after manipulation:

Code:
3.4 4.216
4.6 9.33867
10.8 10.53893
 ...
 ...

Probably there are some perl scripts to do this, in case address me where to find them.

Thank you in advance!
 
Old 03-18-2005, 07:30 AM   #2
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
say file f1 has

average: 4.216
average: 9.33867
average: 10.53893
...
...

and file f2 has
3.4
4.6
10.8

then cut -d":" f1 | paste f2 -
will give you the output
3.4 4.216
4.6 9.33867
10.8 10.53893
...
...

tell me if you are still interested in a perl script (I can cook one for you)
 
Old 03-18-2005, 08:49 AM   #3
rohr
Member
 
Registered: Jan 2005
Distribution: debian
Posts: 44

Original Poster
Rep: Reputation: 15
thanks it works,

but now i want to redirect standard output of this command:
Code:
 cut --fields=2  f1 | paste f2 -
to a file, say f3.
Is this attempt correct?
Code:
 cut --fields=2  f1 | paste f2 > f3
unfortunately i get only a file with the first column of f2 in it.

Any idea?
 
Old 03-18-2005, 09:04 AM   #4
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
cut -d":" --fields=2 f1 | paste f2 - > f3
you missed the -d":" to get only the number part in f1 and also the -
 
Old 03-18-2005, 09:14 AM   #5
rohr
Member
 
Registered: Jan 2005
Distribution: debian
Posts: 44

Original Poster
Rep: Reputation: 15
Smile

thank you!
it works now
 
  


Reply



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
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
Extracting a specific line from an ASCII file heyyou Programming 7 03-21-2005 04:19 PM
File Numbering Conventions soopafresh Linux - Newbie 1 10-24-2004 12:47 AM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM
Displaying a text file in ascii?? bauld Linux - General 4 11-21-2001 07:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:33 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration