ls in specific columns

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions ls in specific columns
# 8  
Old 11-09-2011
I think maybe this work
Code:
ls -t *.* > temp/files.txt
ls -pt */ >temp/dir.txt

and after somehow connect the two .txt's to be in columns ....
but i don't find a ls command to appear only the directories...
ls -pt */ gives me also the contents of the directories.
Any ideas??

---------- Post updated at 08:22 AM ---------- Previous update was at 08:21 AM ----------

Quote:
Originally Posted by vgersh99
I'd start with ls -F1
It appears first the files and the the directories... but in columns ??? Smilie

---------- Post updated at 08:28 AM ---------- Previous update was at 08:22 AM ----------

Quote:
Originally Posted by CarloM
I was thinking more that they might be expecting you to use opendir and readdir.
hmmm i don't know to use these two ...
i'll try reading the manual, but i think i must use something easier that i have learned in class ....
# 9  
Old 11-09-2011
a bit ugly and could be improved:
Code:
ls -p | grep '/$' >/tmp/d.$$
ls -p | grep '[^/]$'>/tmp/f.$$
paste /tmp/d.$$ tmp/f.$$
rm /tmp/d.$$ tmp/f.$$

This User Gave Thanks to vgersh99 For This Post:
# 10  
Old 11-09-2011
The -d option stops ls listing directory contents. You could also use find . -type d to list just directories.
This User Gave Thanks to CarloM For This Post:
# 11  
Old 11-09-2011
-UPDATE-
Code:
ls -t *.* > temp/files.txt
ls -1td */ > temp/dir.txt

i have the files' name listed in column at files.txt ans the directories' name listed also in column at dir.txt
Also the lists are time-sorted Smilie
Now i need a way to connect the two .txt's contexts and appear in columns ....
Somehow with
Code:
cat

or
Code:
sort

?!?
Any ideas?? Smilie
# 12  
Old 11-09-2011
Quote:
Originally Posted by giampoul
-UPDATE-
Code:
ls -t *.* > temp/files.txt
ls -1td */ > temp/dir.txt

Now i need a way to connect the two .txt's contexts and appear in columns ....
Any ideas?? Smilie
look into my last post!
This User Gave Thanks to vgersh99 For This Post:
# 13  
Old 11-09-2011
YES !
thanks vgersh99, i didnt knew the command
Code:
paste

I think problem solved !!

Code:
mk dir temp
ls -t *.* > temp/f.txt
ls -1td */ > temp/d.txt
paste temp/f.txt temp/d.txt

Smilie
# 14  
Old 11-09-2011
Or a very small tweek to the original code I posted:

Code:
ls -pt | awk '
    /\/$/ {
        dcol[didx++] = $0;
        if( length( $0 ) > dmax )
            dmax = length( $0 );
        next;
    }
    {
        ccol[cidx++] = $0;
        next;
    }
    END {
        fmt = sprintf( "%%-%ds %%s\n", dmax );
        stop = didx > cidx ? didx : cidx;
        for( i = 0; i < stop; i++ )
            printf( fmt, dcol[i], ccol[i] );
    }
'

If you're needing this from a compiled programme, I'd do the work in the programme.
This User Gave Thanks to agama For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting data from specific columns

i have a file (csv or txt or anything which has 4 columns (id,name,number,location) and it contains data. i want to convert the data of specific columns like name to ooooo and number to 88888 matching the field length of that columns. for example if name column has anthony which is 7, it should... (2 Replies)
Discussion started by: prajaktaraut
2 Replies

2. UNIX for Dummies Questions & Answers

Grep in specific columns

I am trying to search a list of strings from a file and display the string as well as the column in the search file it was found. I dont care about the row. what is wrong with my script? while read line; do awk -v var="$line" '{for(i=1;i<NF;i++) if ($NF==$var) break; print $var FS $NF' }'... (3 Replies)
Discussion started by: senhia83
3 Replies

3. UNIX for Dummies Questions & Answers

Intersection by specific columns

Hi, I'd like to intersect two files by the 4th col of the first file and 6th col of the second file. This is the code I use: awk 'NR==FNR{A;next}$6 File1 File2 However, this is only outputting the second file lines. I'd like to have both lines in a single line separated by a tab. Thanks in... (25 Replies)
Discussion started by: a_bahreini
25 Replies

4. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

5. Shell Programming and Scripting

Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes. Is there a search for that? I tried cut but couldn't get it to work. Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print... (12 Replies)
Discussion started by: Drenhead
12 Replies

6. Shell Programming and Scripting

Deleting specific columns

Hi group, Can you please tell how to delete specific columns from a file. I know something like awk -F, '{ print $1" "$2" "15 }' input.txt > output.txt will delete all other columns. But this is in a way to copy some particular columns. But is there any other way to select just some... (11 Replies)
Discussion started by: smitra
11 Replies

7. UNIX for Dummies Questions & Answers

How to delete all columns that start with a specific value

I have this space delimited large text file with more than 1,000,000+ columns and about 100 rows. I want to delete all the columns that start with NA such that: File before modification aa bb cc NA100 dd aa b1 c2 NA101 de File after modification aa bb cc dd aa b1 c2 de How would I... (3 Replies)
Discussion started by: evelibertine
3 Replies

8. Shell Programming and Scripting

Replace specific columns in one file with columns in another file

HELLO! This is my first post here! By the way, I think it is great that people do this. My question: I have two files, one is a .dilm and one is a .txt. It is my understanding that the .dilm file can be treated as a .txt file. I wrote another program where I was able to manipulate it as if it... (3 Replies)
Discussion started by: mehdib
3 Replies

9. Shell Programming and Scripting

Mean of the specific columns

I have a input file that has some common values in 1st,2nd and 3rd columns. 4th and 5th are different. Now I would like to print the mean of the fourth column of similar values in 1st.2nd and 3rd columns along with all the values in 5th column. input NM_0 1.22 CR5 0.4 n_21663... (10 Replies)
Discussion started by: repinementer
10 Replies

10. Shell Programming and Scripting

Replace specific columns

hi All, Thi sis very urgent. I have large files with pipe delimited. For example: 1.txt 1001024|120|9|-0.0|#| 1001025|120|9|#| 1001026|120|9|#| 1001032|120|2|-0.0|#| 1002026|110|9|#| 1002027|110|9|-0.0|#| 1002028|120|1|1.0|#| I need to replace the 4th filed if it is # by |-| my... (2 Replies)
Discussion started by: jisha
2 Replies
Login or Register to Ask a Question