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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help editing textfile for use on spreadsheet 1

Status
Not open for further replies.

d3funct

MIS
Jul 13, 2000
313
US
Hi,

I'm trying to take a file that I created just using "ls -laR" and I want to put it in a spreadsheet. The file will eventually be a document inventory in HTML format for our Intranet site at work. It currently looks like this:

38400 Dec 2 1999 bookmark.ntf
297 Jun 21 16:47 adsm.txt.txt
24576 Apr 17 2000 Weekly Project Report for April 10-16.doc

{and several other files, but this is just an example}

Now my question is, is there an AWK or SED statement I can use to create a seperator for these files? I want to seperate the filesize from the date statement, and the filename. I don't care if the seperator is a tab or a character. The problem I'm running into is if I define a single space for substitution it also hits the filenames that have spaces in the name. Plus some of the lines are 2 spaces not just one. It's very inconsistent, but if I can just say, column one is for filesizes, column two looks like a date, and column three is what is leftover.

Thanks for the help d3funct
zimmer.jon@cfwy.com
The software required `Windows 95 or better', so I installed Linux.

 
The following will put commas as the field delimiter.
Code:
awk '{print $1","$2" "$3" "$4","$5}' file > newfile
 
To handle the file names with spaces you need something like

{
printf("%s,%s %s %s,",$1,$2,$3,$4)
for (i=5;i<=NF;i++) printf(&quot;%s &quot;,$i)
print &quot;&quot;
}

This will contract multiple consecutive spaces in a filename into one space. If this is a problem we will need to do something different.

Hope this helps.
CaKiwi
 
This sed statement will also do it and without changing the spaces in the filename.

sed &quot;s/\([^ ]*\) *\([^ ]* *[^ ]* *[^ ]*\) */\1,\2,/&quot; file

Hope this helps.

CaKiwi
 
Thanks for the quick and helpful answers. They all did what I was looking for. Very helpful, thanks. d3funct
zimmer.jon@cfwy.com
The software required `Windows 95 or better', so I installed Linux.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top