Results from "ls" command


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Results from "ls" command
# 1  
Old 11-24-2003
Results from "ls" command

Hello,

I am uning IRIX64. I need to do an ls - 1 (one) command in order to get a one colum listing of the contents of a non current directory:

t01:~ [119] > ls -1 /scratch/u118807/reconstruct
./
../
fr000202.rec
fr000202.sin
input_files/
input_files.tar
sin000000.rec
sin000000.sin
sym000000.raw

Now, I need to list ONLY the files with extensions .raw, .sin, or .rec as follows:

t01:~ [120] > ls -1 /scratch/u118807/reconstruct/*.{rec,raw,sin}
/scratch/u118807/reconstruct/fr000202.rec
/scratch/u118807/reconstruct/fr000202.sin
/scratch/u118807/reconstruct/sin000000.rec
/scratch/u118807/reconstruct/sin000000.sin
/scratch/u118807/reconstruct/sym000000.raw

The problem above is that I do not want the path in front of the files, I only want the filenames by themselves:

fr000202.rec
fr000202.sin
sin000000.rec
sin000000.sin
sym000000.raw

I do not want to "cd" to the directory "/scratch/u118807/reconstruct" to achieve what I want, I want to do everything from the home directory.

I tried using pipes in order to do this, but it did not work.

Any ideas?

Thanks,
--CS
# 2  
Old 11-24-2003
Try:
ls -1 /scratch/u118807/reconstruct/*.{rec,raw,sin} | sed 's=.*/=='
# 3  
Old 11-24-2003
Here you go...


ls -la /path/to/files/{*.rec,*.sin} |awk -F\ / '{ print $NF }'

the \ / Is to remove the special significance of the / so that UNIX will see it as a normal text character and not a special character...

$NF will print the last Field of a line the -F\ / uses the / as a field delimiter...
# 4  
Old 11-24-2003
Thank you both! The two solutions worked. I wonder what is the 's=.*/=='.

--Cecilia.
# 5  
Old 11-24-2003
if i m not wrong = is just another command seperator as in /
for eg we can use s/<firstpattern>/<secondpattern>/g

here / acts as the seperator, but in case ur string has / then u might go for \/ or other seperators as ?, = etc

correct me if i m wrong. by the way i thing the term seperator i used is wrong, what is it called anyway

thanks
# 6  
Old 11-24-2003
oh forgot about the .*

. means any printable character and * is any number of occurences of the character preceding the *

so s=.*/==' means
s --- search
= --- the separator that i talked before of
.*/ -- occurence of any character (.) folowed any number of times (*) and ending with a slash (/)
= --- replace the above searched pattern with
= --- this is more like a ''= meaning replace with null and end the command

hope this is explainable enough
I would suggest you to study about sed, ed etc to help u understand these things better

warm regards
# 7  
Old 11-24-2003
You were right about the separator '='. I tried:

's/.*\///'

And it works exaclty the same!

Thank you all for your help.

--Cecilia.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search file containing ps results for a match "my.cnf" and then for a second match . "ok:" and

I need to find two matches in the output from ps. I am searching with ps -ef |grep mysql for: my.cnf /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/mysql/master/agis_core/etc/my.cnf after this match I want to search back and match the hostname which is x number of lines back, above the... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. UNIX for Dummies Questions & Answers

Confused over results using "tee" in piped command

First post here, so hopefully all guidelines are followed, and thanks in advance for any replies. I'm working on a shell script(BASH) that processes a csv file and performs various tasks with the data. All is well, except I want to use 'tee' to send output from 'wc' to a file as well as pipe it... (4 Replies)
Discussion started by: jazzmusic
4 Replies

5. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

10. UNIX for Dummies Questions & Answers

how to install "source" command!/ broken "login.cl"!

Hello, I am new to this forums and this is my first "asking help" message! i have 2 problems: 1- for unknown reasons the "source" command is not avalable in my system (UBUNTU). i can't either see it in my bin directory! 2- again for unknown reasons the "login.cl" file in the home... (0 Replies)
Discussion started by: astrosona
0 Replies
Login or Register to Ask a Question