is LS a fixed length? I want to use cut -c#-# to isolate filename.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers is LS a fixed length? I want to use cut -c#-# to isolate filename.
# 1  
Old 06-10-2005
is LS a fixed length? I want to use cut -c#-# to isolate filename.

-rw-r--r-- 1 fxpbftp fusion 368 Jun 10 08:34 FX_1.11840235236594E12.111234236809956

If I have a long list of files that look like this (they al begni with FX_1.#######.####) Sometimes, there may be less numbers or more in the filename, that varies.

I wish to isolate just the filename from this LS... how would that look like?

do I use

ls -al | cut -c#-# ? Is the LS always a fixed length (up to the filename)?
# 2  
Old 06-10-2005
Quote:
Originally Posted by yongho
-rw-r--r-- 1 fxpbftp fusion 368 Jun 10 08:34 FX_1.11840235236594E12.111234236809956

If I have a long list of files that look like this (they al begni with FX_1.#######.####) Sometimes, there may be less numbers or more in the filename, that varies.

I wish to isolate just the filename from this LS... how would that look like?

do I use

ls -al | cut -c#-# ? Is the LS always a fixed length (up to the filename)?
If you only want the filename why not just use ls without flags?
# 3  
Old 06-10-2005
not withstanding DogDay's question.....

[assuming the files don't have embedded spaces in their names]
Code:
echo '-rw-r--r-- 1 fxpbftp fusion 368 Jun 10 08:34 FX_1.11840235236594E12.111234236809956' | sed 's/.* \([^ ][^ ]*\)$/\1/'

# 4  
Old 06-10-2005
thanks

I could use LS but, I guess I should've said what I wanted to do.
Later on, I need to cut up the rest of the LS, such as the date of the file's submission and perform some let expr operations on them.

Thank you.
# 5  
Old 06-10-2005
use awk

Quote:
Originally Posted by yongho
-rw-r--r-- 1 fxpbftp fusion 368 Jun 10 08:34 FX_1.11840235236594E12.111234236809956

If I have a long list of files that look like this (they al begni with FX_1.#######.####) Sometimes, there may be less numbers or more in the filename, that varies.

I wish to isolate just the filename from this LS... how would that look like?

do I use

ls -al | cut -c#-# ? Is the LS always a fixed length (up to the filename)?

ls -l | awk '{print $9}'
# 6  
Old 06-10-2005
Quote:
Originally Posted by ramkumar_gr
ls -l | awk '{print $9}'
if you want to go awk route....
[once again - assuming no embedded spaces in the file names]

ls -l | nawk '{print $NF}'
# 7  
Old 06-10-2005
could I really use AWK?

The default delimiter in AWK is [:space:] but the problem is.. (the post didn't paste all the spaces). Between some of the fields, there are 2 spaces, sometimes even 4 spaces.. etc..

Can awk identify variable space delimiters? This is why I didn't want to use awk for the LS. Correct or incorrect?

And yes, you're correct, there are no spaces in filenames.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies

2. Shell Programming and Scripting

Fixed length fields

HPUX and posix shell Hi all. I have a record with fixed length fields....I would like to reorder the fields and preserver the fixed lengths.... cat test 4 960025460 Dept of Music 8 960025248 Dept of Music 12-08 cat... (3 Replies)
Discussion started by: lyoncc
3 Replies

3. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

4. Shell Programming and Scripting

Using cut command in a fixed length file

Hi, I have a file which have set of rows and has to create separate files based on the id. Eg: 001_AHaris020 001_ATony030 002_AChris090 002_ASmit060 003_AJhon001 Output: I want three files like 001_A.txt, 002_A.txt and 003_A.txt. 001_A.txt should have ... (4 Replies)
Discussion started by: techmoris
4 Replies

5. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

6. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

7. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

8. Shell Programming and Scripting

Fixed length (Fill out)

hello, I have a file that has lines with different lengts. I want this file to be filled up with a zero so that al the lines have the same length. Please advice? File 1: ----------- 2310 2009 830 1345 Result File 2: ---------- 2310 2009 0830 (3 Replies)
Discussion started by: peterk
3 Replies

9. Shell Programming and Scripting

fixed record length

hello! I have a file with fixed record length... format: 123445asdfg 4343777 sfgg I wanna convert it to 123445,asdfg ,4343,777 ,sfgg is there any way to do it? sed/grep/awk?? at the moment I use sed -e 's_ \(\)_,\1_g' but it works only if there are spaces between... (16 Replies)
Discussion started by: george_
16 Replies

10. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies
Login or Register to Ask a Question