Skip to main content

All Questions

4 votes
4 answers
313 views

BASH - Find file with regex - Non-recursively delete number-only filenames in directory

I'm wanting to non-recursively delete all files in a directory where each filename contains only numbers, using only a single line of BASH. I somehow accidentally ran a shell script with commented out ...
Stev's user avatar
  • 61
3 votes
2 answers
541 views

How do quotes work in bash regex regarding reserved characters?

Is there any special bash reserved characters in bash regex expression? ex: eg: if [[ $url =~ ^https:\/\/www\.youtube\.com\/playlist\?(.+&)?list= ]]; then echo "URL matches the regex"; ...
Nor.Z's user avatar
  • 133
-1 votes
2 answers
425 views

How to get complex regex to work in bash

The idea is to get a rudimentary check on input pattern for a url: $ ns='abc.def.com' $ reg_expr="\N*\.(\D{2}|\D{3})$" $ echo $reg_expr \N*\.(\D{2}|\D{3})$ $ [[ $ns =~ "$reg_expr" ]...
preetam's user avatar
  • 127
1 vote
2 answers
166 views

sed -Extended RegEx question here

I feel dumb as a sack of hammers asking this here, but it's been a long day and I simply CANNOT figure out what I'm doing wrong here. I have a file; we'll call it textfile.txt. It's contents are (in ...
NerdyDeeds's user avatar
0 votes
1 answer
599 views

regular expression - command not found on terminal

I am trying to grab my_name 369 from file.txt I input this grep line with regex but it return an error. I have tried using egrep and it did not work. Input: my_name 369 == match my_name 161 == match ...
JakePaul's user avatar
0 votes
2 answers
207 views

move recently created files matching a pattern from one folder to a different one

I am looking for a bash script example which does the following: I have files being written under /tmp folder I do at the xterm prompt, ls -ltr which gives me a list of recent files such as: ...
Eric's user avatar
  • 3
1 vote
4 answers
1k views

Grep number behind path, tab and space in a string

Given a string s s="B /home/BL/004_010_0100.0 23 0.031" How can I grep only the number behind the path, tab and space in a string? In the string s above, I'd like to extract the ...
GeoRie's user avatar
  • 33
2 votes
1 answer
1k views

bash conditional expression and backslash escaping [duplicate]

I've really hard time to understand this behaviour: stackExchange@test:~$ if [[ "two words" =~ \bwords ]]; then echo hi; fi; #(I'd expect this one worked) stackExchange@test:~$ if [[ "...
Taz's user avatar
  • 23
1 vote
0 answers
5k views

Working regex does not match in bash [duplicate]

i have a CIDR range in this regex ^5\.188\.62\.([1-9]?\d|[12]\d\d)$ I am able to confirm matching values using https://regexr.com Now i am testing some code and i am using the following as a sample ...
Walter Scarcella's user avatar
1 vote
1 answer
1k views

bash script for creating a text file with all files with specific ending

I know this is a bloody beginner question. But maybe someone has a short answer on this one. In my folder I have several files that end on .SAFE. There are files with different endings though aswell......
Robin Kohrs's user avatar
5 votes
3 answers
3k views

Convert only parts of a filename to uppercase

In a shell script program, I need to convert the filenames to uppercase if the converted filename does not already exist. In this particular case I need to change only the basename to uppercase ...
Esha's user avatar
  • 193
2 votes
3 answers
1k views

Shell script, get/extract mac address from console output of command after "MAC: "

I'm trying to automatically pull out the mac address of a arduino device using a shell script, and need some help how to do this. This is the output returned by the command: Opening /dev/cu....
sMyles's user avatar
  • 2,725
1 vote
2 answers
4k views

How to negate regex using test

This is syntactically wrong: #!/usr/bin/env bash dimension="4x5" if [[ "$dimension" !=~ '[0-9]x[0-9]' ]]; then echo 'wtf meng, the dimension needs an "x" in it.' return 1; fi the above has bad ...
Alexander Mills's user avatar
4 votes
2 answers
467 views

Search For Three Consecutive Words

There are duplicates in my booklist (txt file) like the following - The Ideal Team Player The Ideal Team Player: How to Recognize and Cultivate The Three Essential Virtues Ideal Team Player: ...
Ahmad Ismail's user avatar
  • 2,978
0 votes
4 answers
1k views

How to extract the CSV file name from each line of this file

I have a file which contains lines like those: -rw-rw-rw 1 root root 6379 May 24 2016 test1.CSV -rw-rw-rw 1 root root 23249 May 25 2016 test2.CSV -rw-rw-rw 1 root root 2995 May 26 2016 test3.CSV ...
Ayoub Hammami's user avatar

15 30 50 per page