Assuming that there are not too many files in the directory and that these file-names do not contain spaces, you may try
Spaces are not a problem there. Filenames with a leading dash would cause a problem because they'd be processed as a command option. Using grep -lE -- ... would protect against that. Other than that, the only filename character that will cause a problem with that command is a newline. Since grep -l output is "%s\n", filename, if the filename itself contains a newline, it's impossible to distinguish between a newline from a filename and a newline added by grep to separate filenames.
In my humble opinion, spaces in filenames are not a big deal. However, anyone who uses tabs or newlines in a filename deserves what they get, , because most UNIX tools are designed for text files, which are defined to consist of newline-terminated records with tab-delimited fields.
The * can handle any valid filename just fine. The shell performs pathname expansion (aka file globbing) of wildcards like * and ? after field splitting (which is where whitespace, specifically IFS whitespace characters, can be problematic). Since field splitting has already occurred by the time * is expanded, it's not possible for a space to cause the filename to be split into multiple words. Pathname expansion is the penultimate step in the shell's parsing sequence (only quote removal occurs afterward, which is nothing but the removal of single and double quotes which were present at the start of processing).
For the same reason, for filename in *; do .... done can safely handle any valid filename, regardless of how many spaces, tabs, newlines, or shell metacharacters (e.g. $) it may contain, because the resulting pathname arrives so late in command line processing that the parsing phases which recognize special characters (command substitutions, parameter expansions, field splitting, etc.) have all already completed.
What is wrong in this:
One file in /tmp is test.txt...file has three rows as follows:
YES I M HERE
12345
67890
Second file test2.txt:
status = `grep -i "YES I M HERE" /tmp/test.txt`
print "$status"
if we execute test2.txt It is returning 'status' not found (4 Replies)
Hi One to All
iam new this site,i hopei will get some response for my question.
My requirement is:i will pass a string(i.e Account number), it should search the corresponding log file in the path, after that it should copy the file in particular path, before that it should ask the path... (3 Replies)
Hi All
Iam new this forum,
just i want know someting about the files:
My req: i have file in that i want to search one string, if it is avaible then show the line ,otherwise it will show that the string is not available in the file,
for this i am useing if then else with out - q... (1 Reply)
Hi Everyone,
I am new to this forum and new to sed/awk programming too !!
I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column.
file 1:
(assert (=... (21 Replies)
Hi all,
I have a question..
Here is my requirement..I have 500 files in a path say /a/b/c
I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Dear all,
I need your help, I have file like this:
file1:23456
01910964830098775635
34567
01942809546554654323
67589
26546854368698023653
09778
58716868568576876878
08675
86178546154065406546
08573
54165843543054354305
.
.file2:
23456 25
34567 26
67589 27 (2 Replies)
Hi All,
I'm trying to insert a string into a file at a specific location.
I'd like to add a string after the parent::__construct(); in my file.
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
function... (6 Replies)
Hello
I would like to get know how to do this:
I got a big file (about 1GB) and I need to find a string (for instance by grep )
and then find all records in this file based on a string.
Thanks for advice.
Martin (12 Replies)
Hello Forum.
I have a file called abc.sed with the following commands;
s/1/one/g
s/2/two/g
...
I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat
sed -f abc.sed abc.dat >... (10 Replies)