How to get list of files only using ls without combining it with other command?
HI,
I have requirement to fetch the list of files except the ok file by connecting to other server and then copy all the files that are fetched using the below command.
The above code is also picking up any directory names and dumping the same in filelist.dat. While I am trying to copy the files using the names present in filelist.dat, scp is failing for directory names.
How can I pick up only file names and not the directory names using my first command.
I have requirement to fetch the list of files except the ok file by connecting to other server and then copy all the files that are fetched using the below command.
OK. But this code:
has never run, will never run and definitely not do what you want.
First, ls ${aSrcDIR}/grep should probably read ls ${aSrcDIR}|grep, because otherwise you ask for a directory named "grep", which is located in "${aSrcDIR}" instead of filtering ls ${aSrcDIR} through grep.
Second, "OK$" will not work because "$" is special to the shell and need to be protected. In fact it might even need to be protected twice, first against the local system interpreting the commandline and second against the interpretation of the remote machine.
Finally, you called the file "ok" above and now you call it "OK". These are two different files, because UNIX is case-sensitive (in case you didn't know and it wasn't a simple typo).
At last, in the title you said you do not want to use any other command combined with ls, but in fact you use grep. This *is* an external command. Please, care to explain which it should be now?
If you want to use no other command you will have to use find instead of ls because the latter won't be able to do what you want on its own. If you want to allow grep you can use the "-F" switch of ls (see man ls for details) and use grep to filter the directories.
Quote:
Originally Posted by Nikhath
How can I pick up only file names and not the directory names using my first command.
Short answer: you can't, because your command is faulty, for reasons stated above. You either have to change your command or your expectations.
Thanks for the correction. The first code fragment contains a typo. It is actually a combination of ls and grep.
Here , I am trying to connect to aSrcHOST and fetch the list of files names present in aSrcDIR by filtering out ok/OK files. Hence using grep -vi
This is working fine and fetching all the file names except files ending with ok/OK and dumping the list of files names in filelist.txt.
But , this command is also picking up the sub directory names inside in aSrcDIR.
This is what I want to avoid. I want only files to be picked up and not the directory names.
ls cannot do this. Neither can grep magically tell apart directories and files without some systematic difference between names. You'll have to use a different way.
But , this command is also picking up the sub directory names inside in aSrcDIR.
This is what I want to avoid. I want only files to be picked up and not the directory names.
I said it already above, but i will say it again: have a look at the "-F"-option of ls. Filenames will remain unchanged while directories will be added a "/" at their names:
This should be something you can easily grep for, no?
i am having 2 files like this
file 1
1,
2,
3,
4,
file2
5,
6,
7,
8,
what i want do is like this
i want to put all the contents for file 2 after file 1,means adding column in file1 (5 Replies)
Hi All,
Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below,
1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Hi,
I have two list I wanna combine and print them together in the output depending if they have the same rsid:
file1:
ENST00000262042 rs47 583 N D
ENST00000408005 rs48 583 N D
ENST00000311322 rs268 318 N S
file 2:
rs34 CHB T 1 C 0 T/T C/T C/C 1 0 0
rs47 JPT T 1 C 0 T/T C/T C/C 1 0 0
rs48... (6 Replies)
Hi Gurus,
I have 2 files:
File1
Filename1 xx
Filename1 yy
Filename1 Total
Filename2 xx
Filename2 yy
Filename2 zz
Filename2 Total
Filename3 xx
Filename3 Total
and File2:
Filename1 10296 xxx Date: 09/01/08
Filename2 10296 xxx Date: 09/05/08... (36 Replies)
Hi All,
I have a file in DirA/ABC.out a need to move to DirB.I am using the following steps now:
mv DirA/ABC.out DirB
compress -f DirB/ABC.out
Is there a way to just do this one step as I have to move hundreds of files every hour.
-Thanks in advance. (4 Replies)
I have two files and I need to combine (not append - but combine a row to a row)
eg:
File1:
apples
grapes
oranges
lemons
File2:
red
green
orange
yellow
After combining, the file should look like: (the second column should start at a specific byte)
apples red
grapes green... (7 Replies)
Could someone help me reduce the number of runs for a shell program I created?
I have two text files below:
$ more list1.txt
01 AAA
02 BBB
03 CCC
04 DDD
$ more list2.txt
01 EEE
02 FFF
03 GGG
I want to combine the lines with the same number to get the below:
01 AAA 01 EEE
02... (4 Replies)
Hi,
is there a way to combine 2 files together, joining line 1 from file A with line 1 from file B, line 2 from A with line 2 from B etc.
File A File B
1 4
2 5
3 6
Combined result =
File C
14
25
36 (2 Replies)
how will i combine these 2 files below, with the desired output
specified below:
file1:
one
two
three
four
file2:
red
blue
yellow
green
file3:
aaa
bbb
ccc
ddd (3 Replies)