Sponsored Content
Full Discussion: Combining multiple greps
Top Forums UNIX for Beginners Questions & Answers Combining multiple greps Post 303031223 by Scrutinizer on Sunday 24th of February 2019 06:17:31 AM
Old 02-24-2019
With regards to pattern matching, perhaps a finer point to be made here is that (standard) globbing, or glob pattern matching, is a special form of pattern matching, where patterns are used for filename expansion.

In pattern matching, the wildcards are *, ? or a bracket expression ( [ ... ] )

In the case of globbing there are the following extra rules:
  • Wildcards do not match files that start with a . (dot) (those can be matched by specifying a dot as the first character in the pattern)
  • Wildcards do not match / (forward slash).
  • A forward slash cannot be used in a bracket expression (doing so turns the bracket expression into a literal string).

Globbing results in a list of files if there is a match, or the pattern itself if there is no match. The order in which the list of files is presented is governed by LC_COLLATE.
See Patterns Used for Filename Expansion


Examples:
Code:
$ mkdir -p somedir/foo
$ touch a.b .a.b somedir/bar somedir/.baz somedir/"foo bar"
$ ls -d *
a.b	somedir
$ ls -d .*
.	..	.a.b
$ ls -d * .*
.	..	.a.b	a.b	somedir
$ ls -d * .[!.]*
.a.b	a.b	somedir
$ ls -d */*
somedir/bar	somedir/foo	somedir/foo bar

Compare this to regular pattern matching, where a slash is actually matched
Code:
$ ls -d somedir/foo | while read line; do case $line in (*) echo "$line"; esac; done
somedir/foo

--
The bash shell and other more modern shells, like ksh93 and zsh also support extended globbing with additional rules.

Last edited by Scrutinizer; 02-24-2019 at 07:32 AM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining multiple lines

I am fairly new to scripting. But I have been able to extract and format all of my information required into one file. My issue is that one character is on a separate line. I need to be able to add the character to the previous line. ex. abcdefghi 1 bcdefghij 3 cdefghijk 4 need to... (4 Replies)
Discussion started by: DUST
4 Replies

2. Shell Programming and Scripting

Sed: Combining Multiple Lines into one

Before I ask my actual question, is it going to be a problem that I want to run this process on a 15 Gig file that is ~140 million rows? What I'm trying to do: I have a file that looks like Color,Type,Count,Day Yellow,Full 5 Tuesday Green,Half 6 Wednesday Purple,Half 8 Tuesday ...... (3 Replies)
Discussion started by: goldfish
3 Replies

3. Shell Programming and Scripting

Combining multiple commands

Hi Guys, I am looking to optimze these 5 SSH lines to a single SSH to get my machine to not hang! lol! cat hosts.lst | xargs -n1 -t -i echo 'home/util/timeout 6 0 ssh -q {} top -b > util/{}.top &' >> r_query_info cat hosts.lst | xargs -n1 -t -i echo 'home/util/timeout 6 0 ssh -q {} uname -r... (5 Replies)
Discussion started by: wick3dsunny
5 Replies

4. Shell Programming and Scripting

Combining multiple files into one with the same name/different extension

I've been trying to find information in regard to creating a script that will generate HTML files. I currently have a series of files that contain code I need to surround with a <textarea> tag for easy viewing. I have about a thousand files that contain code, one file that contains the HTML code up... (10 Replies)
Discussion started by: 12o
10 Replies

5. Shell Programming and Scripting

Combining multiple variables into new variable

Hello, I am a new joiner to the forum, and have what i hope is a simple question, however I can't seem to find the answer so maybe it is not available within bash scripting. I intend to use the below script to archive files from multiple directories at once by using a loop, and a variable (n)... (10 Replies)
Discussion started by: dring
10 Replies

6. Shell Programming and Scripting

combining multiple sed statements

I need to run a cronjob that will monitor a directory for files with a certain extension, when one appears I then need to run the below scripts How do I go about combining the following sed statements into one script? and also retain the original filename.? sed 's/71502FSC1206/\n&/g' # add a... (2 Replies)
Discussion started by: firefox2k2
2 Replies

7. Shell Programming and Scripting

Bash Scipting (New); Run multiple greps > multiple files

Hi everyone, I'm new to the forums, as you can probably tell... I'm also pretty new to scripting and writing any type of code. I needed to know exactly how I can grep for multiple strings, in files located in one directory, but I need each string to output to a separate file. So I'd... (19 Replies)
Discussion started by: LDHB2012
19 Replies

8. Shell Programming and Scripting

Combining multiple files

I have 2 files. each having 3 coloums 1st field date as 20130322 2nd field time as 05:55 3rd field numberic value File 2 has entries missing for some date time. FILE1 20130322 05:35 2219 20130322 05:40 1809 20130322 05:45 1617 20130322 05:50 ... (2 Replies)
Discussion started by: sandeepkmehra
2 Replies

9. Shell Programming and Scripting

Combining multiple seds into one awk

i'm trying to optimize my script. i have a lot of instances where i'm doing something like this: echo $blah | sed 's~ ~|~g' | sed 's-_space_- -g' | sed 's-_LP_-(-g' | sed 's-_RP_-)-g' obviously, this is very inefficient. i know i can combine into one sed command with something this, using... (7 Replies)
Discussion started by: SkySmart
7 Replies

10. UNIX for Beginners Questions & Answers

Combining multiple files into one

Hello Everyone, I have 4 different files (one column in each) that I'm trying to combine into 1 file with four columns. Having issues trying to get the columns to format properly. I have tried the following: paste file1 file2 file3 file4 | column -s $'\t' -t > results.txt paste file1 file2... (1 Reply)
Discussion started by: malk71
1 Replies
All times are GMT -4. The time now is 12:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy