Failure using regex with awk in 'while read file' loop
I have a file1.txt with several 100k lines, each of which has a column 9 containing one of 60 "label" identifiers. Using an labels.txt file containing a list of labels, I'd like to extract 200 random lines from file1.txt for each of the labels in index.txt.
Using a contrived mini-example:
This is what I'm trying, but it results in empty files:
Desired output--two random lines for each label in labels.txt (i.e. may vary except for "label=c12" or "label=g12", respectively):
It seems like the problem is with the " awk '/${file}/' "? I say this because I can extract lines for each label but only if I explicitly specify the label regex (in this case g10.txt also has two random lines with "label=c12" instead of g10):
Thanks for any pointers.
Hello all,
I need some help to create a script which contain a few strings on every line, and use those strings in a loop to fire some commands.
for exmaple the file looks like
tom
dave
bill
andy
paul
I want to read one line at a time and use it in loop like
command tom
command dave... (3 Replies)
Guys,
I am trying to read the whole file using while loop but when i run the ssh part of the script it reads only the first line and exit after that.
There are in total 134 lines in the file, but when the output is redirected, it does only for one line and comes to command prompt.
pls help..... (11 Replies)
Hi
As a newbe in scripting, i struggle hard with my first script.
What i want to do is, bringing data of two files together.
file1:
....
05/14/12-04:00:00 41253 4259 5135 5604 5812 5372
05/14/12-04:10:00 53408 5501 6592 7402 7354 6639
05/14/12-04:20:00 58748 6037 7292 8223... (13 Replies)
I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header.
In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Hello,
I have a huge file, I am currently using while loop to read and do some calculation on it, but it is taking a lot of time.
I want to use AWK to read and do those calculations.
Please suggest.
currently doing:
cat input2 | while read var1
do
num=`echo $var1 | awk... (6 Replies)
Hello,
I have a set of files Xfile0001 - Xfile0021, and the content of this files (one at a time) needs to be printed between some line (lines start with word "Generated") that I am extracting from another file called file7.txt and all the output goes into output.txt. First I tried creating a for... (5 Replies)
I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix.
I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice.
Files:... (3 Replies)
Hi everybody,
I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o
My code:
#!/bin/sh
set -e
set -u
export IFS=
optl="Optl"
LOCSTORCLI="/opt/lsi/storcli/storcli"
($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies
LEARN ABOUT PHP
glob
GLOB(3) 1 GLOB(3)glob - Find pathnames matching a patternSYNOPSIS
array glob (string $pattern, [int $flags])
DESCRIPTION
The glob(3) function searches for all the pathnames matching $pattern according to the rules used by the libc glob() function, which is
similar to the rules used by common shells.
PARAMETERS
o $pattern
- The pattern. No tilde expansion or parameter substitution is done.
o $flags
- Valid flags:
o GLOB_MARK - Adds a slash to each directory returned
o GLOB_NOSORT - Return files as they appear in the directory (no sorting). When this flag is not used, the pathnames are
sorted alphabetically
o GLOB_NOCHECK - Return the search pattern if no files matching it were found
o GLOB_NOESCAPE - Backslashes do not quote metacharacters
o GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c'
o GLOB_ONLYDIR - Return only directory entries which match the pattern
o GLOB_ERR - Stop on read errors (like unreadable directories), by default errors are ignored.
RETURN VALUES
Returns an array containing the matched files/directories, an empty array if no file matched or FALSE on error.
Note
On some systems it is impossible to distinguish between empty match and an error.
CHANGELOG
+--------+--------------------+
|Version | |
| | |
| | Description |
| | |
+--------+--------------------+
| 5.1.0 | |
| | |
| | |
| | GLOB_ERR was added |
| | |
+--------+--------------------+
EXAMPLES
Example #1
Convenient way how glob(3) can replace opendir(3) and friends.
<?php
foreach (glob("*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "
";
}
?>
The above example will output something similar to:
funclist.txt size 44686
funcsummary.txt size 267625
quickref.txt size 137820
NOTES
Note
This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.
Note
This function isn't available on some systems (e.g. old Sun OS).
Note
The GLOB_BRACE flag is not available on some non GNU systems, like Solaris.
SEE ALSO opendir(3), readdir(3), closedir(3), fnmatch(3).
PHP Documentation Group GLOB(3)