Format next line for ls output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format next line for ls output
# 1  
Old 09-26-2015
Format next line for ls output

hi
i have 4 dir called
old-dir1
old-dir2
dir3
dir4
now i need to grep only old dir named
Code:
ls -d  old* > outfile

The output will show as:
Code:
cat  outfile
old-dir1 old-dir2

Desired output is:

Code:
old-dir1
old-dir2


Last edited by raghur77; 09-26-2015 at 08:37 AM.. Reason: i have updated it, not long listing
# 2  
Old 09-26-2015
I must be missing something here:-
ls -ld old* ..... will never give anything like what your cat gives...
Also any file or directory beginning with 'old' will be LONG listed.
How are you filtering the directories to be displayed ONLY...
# 3  
Old 09-26-2015
hi wisecracker,

sorry my bad, i have updated it now
it is ls -d to show only directories
# 4  
Old 09-26-2015
As we have no idea of your current drawer format we have to assume there are files beginning with 'old' too.
ls -d does NOT do what you think it does, read man ls for more info...
but here is my printout of manually doing what you need INCLUDING a file with a beginning section...
Code:
Last login: Sat Sep 26 12:39:07 on ttys000
AMIGA:barrywalker~> ls -ld Des* > /tmp/text
AMIGA:barrywalker~> cat /tmp/text
-rwxr-xr-x   1 barrywalker  staff  154912 26 Sep 12:29 Desk_top.txt
drwx------+ 13 barrywalker  staff     442  8 Sep 20:35 Desktop
AMIGA:barrywalker~> ls -d Des* > /tmp/text
AMIGA:barrywalker~> cat /tmp/text
Desk_top.txt
Desktop
AMIGA:barrywalker~> _

Inside OSX 10.7.5, default bash terminal.
As you can see apart from having a text file with it it is formatting correctly.
And once again how are you filtering the files from the directiores beginning with the same name?
# 5  
Old 09-26-2015
When ls output is directed to a terminal device, it can default to multi-column output. But, when output is directed to a regular file or a pipe, the output should be as you wanted with single-column output.

What operating system are you using?

Is an alias in play? (What output do you get from the command: type ls?)

Try:
ls -1d old* > outfile
Note that the added option is the digit one (not the lowercase letter ell).
# 6  
Old 09-26-2015
Quote:
Originally Posted by wisecracker
As we have no idea of your current drawer format we have to assume there are files beginning with 'old' too.
ls -d does NOT do what you think it does, read man ls for more info...
but here is my printout of manually doing what you need INCLUDING a file with a beginning section...
Code:
Last login: Sat Sep 26 12:39:07 on ttys000
AMIGA:barrywalker~> ls -ld Des* > /tmp/text
AMIGA:barrywalker~> cat /tmp/text
-rwxr-xr-x   1 barrywalker  staff  154912 26 Sep 12:29 Desk_top.txt
drwx------+ 13 barrywalker  staff     442  8 Sep 20:35 Desktop
AMIGA:barrywalker~> ls -d Des* > /tmp/text
AMIGA:barrywalker~> cat /tmp/text
Desk_top.txt
Desktop
AMIGA:barrywalker~> _

Inside OSX 10.7.5, default bash terminal.
As you can see apart from having a text file with it it is formatting correctly.
And once again how are you filtering the files from the directiores beginning with the same name?
If you just want to see directories in a case like this, you can use:
Code:
ls -d Des*/ > /tmp/text

The output will include a trailing slash, but in many cases that won't matter. If the trailing slash is a problem, there are lots of ways to get rid of it depending on how the output is being processed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

3. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

4. Shell Programming and Scripting

Extract Line and Column from CSV Line in ksh or bash format

Hi, I was doing some research and can't seem to find anything. I'm trying to automate a process by creating a script to read a csv line and column and assigning that value to a variable for the script to process it. Also if you could tell me the line and column if it's on another work ... (3 Replies)
Discussion started by: vpundit
3 Replies

5. Shell Programming and Scripting

Modify a perl line to parse out and output to another format

Hey there... I am looking for a way to take the below contents ( small excerpt) of this file called PTR.csv ptrrecord,0000002e0cc0.homeoffice.anfcorp.com,,10.11.191.62,,,False,62.191.11.10.in-addr.arpa,,302400,default... (6 Replies)
Discussion started by: richsark
6 Replies

6. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

7. Shell Programming and Scripting

capturing output from top and format output

Hi all, I'd like to capture the output from the 'top' command to monitor my CPU and Mem utilisation.Currently my command isecho date `top -b -n1 | grep -e Cpu -e Mem` I get the output in 3 separate lines.Tue Feb 24 15:00:03 Cpu(s): 3.4% us, 8.5% sy .. .. Mem: 1011480k total, 226928k used, ....... (4 Replies)
Discussion started by: new2ss
4 Replies

8. Shell Programming and Scripting

how to make a line BLINKING in output and also how to increase font size in output

how to make a line BLINKING in output and also how to increase font size in output suppose in run a.sh script inside echo "hello world " i want that this should blink in the output and also the font size of hello world should be big .. could you please help me out in this (3 Replies)
Discussion started by: mail2sant
3 Replies

9. UNIX for Dummies Questions & Answers

format output from while read line

I have an output that I get from while read, I want to display it as the following, please help. Original output from while read line loop: This is my client=1 client version=2.3.4 OS version=4.5 This is my client=2 client version=1.5.6 OS version=6.7 I want it to look like this with... (7 Replies)
Discussion started by: dala
7 Replies

10. Shell Programming and Scripting

Format a line for output

Hi all I have a problem which requires me to produce a line output in a specified format. I have looked around and see that there is typeset which would do the trick to pad a variable and as such ensure that its start position in a line is always the same. I have tried to use this, however it... (4 Replies)
Discussion started by: jhansrod
4 Replies
Login or Register to Ask a Question