Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

report formatting 1

Status
Not open for further replies.

Mag0007

MIS
Feb 15, 2005
829
US
I have a file like this

ascii
6 /export/home/user/.bash_history
ascii
2 /export/home/user/fe.patch
ascii
2 /export/home/user/.dt/sessions/lastsession

I would like a format of this:
/export/home/user/.bash_history ascii 6
/export/home/user/fe.patch ascii 2
/export/home/user/.dt/sessions/lastsession ascii 2

TIA!

 
A starting point (provided no space in pathnames):
awk 'NF==1{f=$1;next}{print $2,f,$1}' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hmm, thanks for the reply...seems that my file is too long.

Basically this is what I am trying to do.

I have a text file that has full file paths:
/export/user/file1
/export/user/binaryFile
/export/user/larrgeFile


And I would like to get its size, file type, and file name all on one line.

Like:
5 ascii /export/user/file1
2 binary /export/user/binaryFile
23123 binary /export/user/larrgeFile

i have it halfway, but awk is complaining about the file size...BTW I have over 10k files :-(

TIA!



 
How do you get asccii or binary ? By interpreting the output of the file command ?
Anyway I don't see why you need awk.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
phv:
yes, that was just an example. I am getting ascii and binary from the command "file".

I am not sure how else I can show something like that.

for file in `cat outfile`; do
du $file;
file $file;
done;

now, the hard part is putting it all on one line :)

thanks for the response BTW!
 
I have a Perl solution - but only because you stated that awk was complaining

Code:
[b]#!/usr/bin/perl[/b]

open (IN, "< data.txt") or die $!;

while (<IN>) {
  chomp;
  if (m/^(\d+)\s+(\S+)$/) {
    print "$2 $fileType $1\n";
  } else {
    $fileType = $_;
  }
}

close IN;


Kind Regards
Duncan
 
while read file
do
echo "$file `file $file` `du -k $file`
done < outfile

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
hmm,

How can I remove the blank line?

For example:
bash-2.03$ file /tmp/ps_data; du -k /tmp/ps_data
/tmp/ps_data: text
8 /tmp/ps_data

How can I get, "/tmp/ps_data: text 8 /tmp/ps_data"
?

TIA!



 
The same way that PHV did in his last post (see the line with "echo" in it), does that not work for you?

Annihilannic.
 
I just got it!

I am using a temp variable to get them all on one line!

thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top