Results 1 to 3 of 3
I am a beginner SuSE Linux user so my knowledge is very limited on the subject matter so bear with me.
I have a file called file1. file1 has the ...
- 08-28-2008 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 2
Redirect info in file
I am a beginner SuSE Linux user so my knowledge is very limited on the subject matter so bear with me.
I have a file called file1. file1 has the following content inside
Client A
Time 2:00
Date 8/27/08
Pages 23
Space 10000
Client B
Time 3:00
Date 8/28/08
Pages 43
Space 20000
etc... all the way to Z
I am trying to create a file with just this info in this order
Client Date Space
A 8/27/08 10000
B 8/28/08 20000
What do I need to do to adjust the content inside this file? I don't know if I need to use an array or I could do this by using awk or grep commands.
- 08-29-2008 #2
Try Perl
Code:#!/usr/bin/perl # written as basic as I can - I know there are "better ways" # the file you want to open $file = 'file1.txt'; # open and assign to array of INFO open(INFO, $file); # print header (for better way looking into print formatting @<<<) print "Client Date Space\n"; # read a line from the array over and over again while($line = <INFO>) { # clean up the last bit chop($line); # take the line and seperate each field by a space / / @data = split(/ /,$line); # if the line has a "Client" in it do this if($data[0] =~ /Client/) { # display the second item in the array, first item is client :) print "$data[1] "; } elsif($data[0] =~ /Date/) { print "$data[1] "; } elsif($data[0] =~ /Space/) { print "$data[1]\n"; } } # close the file close(INFO);
- 09-02-2008 #3Just Joined!
- Join Date
- Aug 2008
- Posts
- 2
Thanks a lot!
I will try this out and see how it goes.


Reply With Quote