BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
david27
Quartz | Level 8

Hello,

 

I have a text file on unix server which i obtain using the "stat" command.

I am having difficulty reading in the file in separate columns.

 

I want separate column for: file, size , blocks, IO Block, device etc.

Can you please help?

 

Here is how the text file looks(also attached):

 

File: `table_1_201801.sas7bdat'
Size: 106954752 Blocks: 131473 IO Block: 131072 regular file
Device: 7bh/123d Inode: 127058 Links: 1
Access: (0644/-rw-r--r--) Uid: (9999999/ z123456) Gid: ( 940/ team_id)
Access: 2018-11-05 15:36:54.517252096 -0600
Modify: 2018-11-05 15:37:06.645740950 -0600
Change: 2018-11-05 15:37:06.675385515 -0600
File: `table_1_201802.sas7bdat'
Size: 107216896 Blocks: 133841 IO Block: 131072 regular file
Device: 7bh/123d Inode: 127066 Links: 1
Access: (0644/-rw-r--r--) Uid: (9999999/ z123456) Gid: ( 940/ team_id)
Access: 2018-11-05 15:37:28.570265024 -0600
Modify: 2018-11-05 15:37:38.510186494 -0600
Change: 2018-11-05 15:37:38.550049587 -0600
File: `table_1_201803.sas7bdat'
Size: 107610112 Blocks: 131401 IO Block: 131072 regular file
Device: 7bh/123d Inode: 127073 Links: 1
Access: (0644/-rw-r--r--) Uid: (9999999/ z123456) Gid: ( 940/ team_id)
Access: 2018-11-05 15:38:02.027723747 -0600
Modify: 2018-11-05 15:38:12.474856957 -0600
Change: 2018-11-05 15:38:12.512025723 -0600

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@david27 wrote:

@ballardw: Sorry for that un-formatted text being pasted. I saw that and that is why I attached the file.

Regarding Quotes: Yes it is like that.


Just wondered about the quotes as using the data in a datalines block creates unbalanced quotes and I'm not sure whether that would get read correctly as SAS typically will remove single ' or double " quotes around text when reading files.

 

I would expect someone with more recent UNIX experience than mine to have a solution somewhat quickly.

 

This might get you started for some of the bits:

data have;
   infile 'your file name here';
   informat name $42. 
            device $10.
            Permissions $30.
            Accessdate Modifydate Changedate  yymmdd10.
            Accesstime Modifytime Changetime  time18.9
   ;
   format   Accessdate Modifydate Changedate  yymmdd10.
            Accesstime Modifytime Changetime  time18.9
  ;
   input @'File:' name
        /@' Size: ' size @'Blocks: ' blocks @'IO Block: ' IOBlock
        /@'Device: ' device @'Inode: ' Inode @'Links: ' links
        /@'Access: ' Permissions 
        /@'Access: ' Accessdate Accesstime
        /@'Modify: ' Modifydate Modifytime
        /@'Change: ' Changedate Changetime
   ;
run;

@the / tells SAS to read the next line as part of the same record. The @'string' tells SAS to start reading the next value after the text.

 

Since your UID and GID bits have spaces imbedded in them there's going to be some finagling to read them properly and I don't have time to get that right now.

You may need a TRUNCOVER option on the infile.

If this doesn't work to get the filename then that slanted quote is the likely issue and I haven't got a solution at the moment.

View solution in original post

4 REPLIES 4
ballardw
Super User

Paste plain text into a code box opened using the forum's {I} icon to prevent the message windows from reformatting it:

  File: `table_1_201801.sas7bdat'
  Size: 106954752 	Blocks: 131473     IO Block: 131072 regular file
Device: 7bh/123d	Inode: 127058      Links: 1
Access: (0644/-rw-r--r--)  Uid: (9999999/ z123456)   Gid: (  940/  team_id)
Access: 2018-11-05 15:36:54.517252096 -0600
Modify: 2018-11-05 15:37:06.645740950 -0600
Change: 2018-11-05 15:37:06.675385515 -0600
  File: `table_1_201802.sas7bdat'
  Size: 107216896 	Blocks: 133841     IO Block: 131072 regular file
Device: 7bh/123d	Inode: 127066      Links: 1
Access: (0644/-rw-r--r--)  Uid: (9999999/ z123456)   Gid: (  940/  team_id)
Access: 2018-11-05 15:37:28.570265024 -0600
Modify: 2018-11-05 15:37:38.510186494 -0600
Change: 2018-11-05 15:37:38.550049587 -0600
  File: `table_1_201803.sas7bdat'
  Size: 107610112 	Blocks: 131401     IO Block: 131072 regular file
Device: 7bh/123d	Inode: 127073      Links: 1
Access: (0644/-rw-r--r--)  Uid: (9999999/ z123456)   Gid: (  940/  team_id)
Access: 2018-11-05 15:38:02.027723747 -0600
Modify: 2018-11-05 15:38:12.474856957 -0600
Change: 2018-11-05 15:38:12.512025723 -0600

Did the output originally contain those ` slanted quotes at the start of the name?

 

david27
Quartz | Level 8

@ballardw: Sorry for that un-formatted text being pasted. I saw that and that is why I attached the file.

Regarding Quotes: Yes it is like that.

ballardw
Super User

@david27 wrote:

@ballardw: Sorry for that un-formatted text being pasted. I saw that and that is why I attached the file.

Regarding Quotes: Yes it is like that.


Just wondered about the quotes as using the data in a datalines block creates unbalanced quotes and I'm not sure whether that would get read correctly as SAS typically will remove single ' or double " quotes around text when reading files.

 

I would expect someone with more recent UNIX experience than mine to have a solution somewhat quickly.

 

This might get you started for some of the bits:

data have;
   infile 'your file name here';
   informat name $42. 
            device $10.
            Permissions $30.
            Accessdate Modifydate Changedate  yymmdd10.
            Accesstime Modifytime Changetime  time18.9
   ;
   format   Accessdate Modifydate Changedate  yymmdd10.
            Accesstime Modifytime Changetime  time18.9
  ;
   input @'File:' name
        /@' Size: ' size @'Blocks: ' blocks @'IO Block: ' IOBlock
        /@'Device: ' device @'Inode: ' Inode @'Links: ' links
        /@'Access: ' Permissions 
        /@'Access: ' Accessdate Accesstime
        /@'Modify: ' Modifydate Modifytime
        /@'Change: ' Changedate Changetime
   ;
run;

@the / tells SAS to read the next line as part of the same record. The @'string' tells SAS to start reading the next value after the text.

 

Since your UID and GID bits have spaces imbedded in them there's going to be some finagling to read them properly and I don't have time to get that right now.

You may need a TRUNCOVER option on the infile.

If this doesn't work to get the filename then that slanted quote is the likely issue and I haven't got a solution at the moment.

david27
Quartz | Level 8

Thank You Very much @ballardw

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1017 views
  • 2 likes
  • 2 in conversation