Listing file issue


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Listing file issue
# 1  
Old 07-21-2017
Listing file issue

I have the three following files available in the directory. But the job should be able to read only the first two files. Could any one help me in writing command to list only the first two files and omit the last file. I used
Code:
ls -1 LSM_REP* > final.lst

. It is copying all the three files. But I need only first two files to be copied over. Please help me.
Code:
1. LSM_REP_C0097_offonEnf_031217_142706_4819_1of1.csv
2. LSM_REP_C0098_Enfenroll_031217_142706_4819_1of1.csv
3. LSM_REP_C2804_LTYQUARTER_022217_140016_4690_9999_1001_1of1.csv


Last edited by Scrutinizer; 07-21-2017 at 05:50 PM.. Reason: code tags
# 2  
Old 07-21-2017
Hi try:

Code:
set LSM_REP*
if [ $# -ge 2 ]; then
  printf "%s\n" "$1" "$2" > final.lst
fi

or just:
Code:
ls LSM_REP* | head -n2 > final.lst


Last edited by Scrutinizer; 07-22-2017 at 02:54 AM..
# 3  
Old 07-22-2017
or simply
Code:
ls -l LSM_REP_C0* >final.list

# 4  
Old 07-24-2017
It is copying both the files using above commands. The command should be able to separate the files like the following.
Code:
ls LSM_REP_*_*_*_*_*_*_*_*

-- This will list only the below file. Because it has 8 underscores after LDM_REP.
Code:
LSM_REP_C02804_LTYQUARTER_022217_140016_4690_9999_1001_online.csv

Similary, The file with 6 underscores should be separated. If i use 6 underscores it will list both the files. I couldn't figure out a way to separate these files

Last edited by Scrutinizer; 07-24-2017 at 12:30 PM.. Reason: code tags
# 5  
Old 07-24-2017
Quick fix:
Code:
ls -l LSM_REP* | awk -F_ 'NF==8' >outfile

--
or, in bash, try:
Code:
GLOBIGNORE=LSM_REP_*_*_*_*_*_*_*_*
ls -l LSM_REP*


Last edited by Scrutinizer; 07-24-2017 at 12:58 PM..
# 6  
Old 07-24-2017
Wow. That's a good one. It worked. Thank you very much Scrutinizer
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Listing non zero values from file

Legends, I have following contents in the file and i want to list out non-zero values only out of it. OPge1 03 OPge10 121 OPge11 3 OPCge12 0 OPCge13 0 OPge14 25 OPC15 0 I am using following loop; but not getting desired results for line in `cat /tmp/raw` do Name=`echo $line |... (4 Replies)
Discussion started by: sdosanjh
4 Replies

2. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

3. UNIX for Dummies Questions & Answers

Recursively listing of the file

Hi, I want to list out the files for a particular date recursively along with timestamp and directory name . I tried using command ls -lRt this list out all the files along with directory structure but i want for a particular date so i tried with ls -lRt | grep 20110809 in... (9 Replies)
Discussion started by: Abhi2910
9 Replies

4. UNIX for Dummies Questions & Answers

Listing file name and date

Hello. I want to make an unix script which create a file with the name and the date of creation of the different files that there are in a directory. Can do you please help me? Thank you in advance. (3 Replies)
Discussion started by: Jfka
3 Replies

5. Shell Programming and Scripting

How do I get only the file name from a listing?

Hi, I am trying to get a file name only. Could anyone help me on the same. Meaning I have a file say list.out which holds below output ./xyz/abc.txt ./xyz/hij.txt I want an output as below abc.txt hij.txt i.e I want to delete everything before abc.txt Please help me out if any one has... (4 Replies)
Discussion started by: spark
4 Replies

6. Shell Programming and Scripting

listing the latest file

if i am having files as below in a directory---- -rwxrwxrwx 1 dsadm dstage 43 Nov 21 2005 CheckfreeFtpSeq.err -rwxrwxrwx 1 dsadm dstage 37 Jun 22 2007 EDIRemitVendorAdviceSeq.log -rwxrwxrwx 1 dsadm dstage 43 Jun 22 2007 EDIRemitVendorAdviceSeq.err... (2 Replies)
Discussion started by: Sagarddd
2 Replies

7. Solaris

file listing ...

Hi experts, I have several hundred files for everyday each month (below example is September)- PP023149200709010546.......PP028023200709012300 PP023150200709020023.......PP026096200709022134 .. .. PP021256200709201920.......PP025576200709202218 .. ..... (3 Replies)
Discussion started by: thepurple
3 Replies

8. Programming

Listing File Info

Hi, From a Unix book, i'd found that the way to list files in a directory. But those file info are all not shown, wat is shown is only the file name. Can anyone pls teach me how to show the file details? (etc file size, read/write permission, modified date) my code: Dir *dirp; struct... (3 Replies)
Discussion started by: AkumaTay
3 Replies

9. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies

10. UNIX for Dummies Questions & Answers

File listing

I can't seem to list all the files that begin with a lower case or upper case letter between a-m while being in that directory? Please help I've tried everything from all the ls commands to even grep commands. b (5 Replies)
Discussion started by: Astudent
5 Replies
Login or Register to Ask a Question