Skip to main content

All Questions

Filter by
Sorted by
Tagged with
0 votes
2 answers
41 views

Capture and print on the exact match from a file

I am trying to use grep to match only a specific part of a row in a file. The file is a huge csv file with some columns containing json with commas so it is hard to figure out which column what I am ...
smith's user avatar
  • 121
-2 votes
2 answers
1k views

Generate strings from regular expression in bash

How in Bash to generate a string given by a regex expression and pipe it to another command? For example: > $RANDOM | regex "{abcdef\d}[8]" | grep "1{3}" | less I did not find ...
Aycon's user avatar
  • 99
1 vote
1 answer
55 views

fix filenames with wrong starting and ending character(s) in Bash, mass renaming

I need to rename a lot of files by removing the 1st and the last characters (before .ext). WRONG> '1st moto ride [Aug '99]'.mp4 'Samuel' Song'.mp3 'Plane Landing'.avi '"Ode" (sort of) to ...
dAllARA's user avatar
  • 33
0 votes
1 answer
544 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
4 answers
421 views

Changing the name of a file based on a part of its original name that are between the first two instances of a character

I am trying to change the names of my files based on the string between the first two instances of "|". This is what my problem looks like: >1234|interest1|randomstuff1.txt >5678|...
Fernando 's user avatar
-1 votes
1 answer
40 views

bash + verify if file that ended with many combinations exists [duplicate]

we can have the /tmp/file.1 or /tmp/file.43.434 or /tmp/file-hegfegf , and so on so how we can verify in bash if any /tmp/file* exists ? we try as [[ -f "/tmp/file*" ]] && echo "...
yael's user avatar
  • 13.7k
0 votes
1 answer
518 views

sscanf equivalent in shell script

I have a file which has some stats and counters stored for some ACL rules. I want to design a shell script to read that file and parse those counters. I have done the similar thing in c programming ...
vivek's user avatar
  • 131
0 votes
1 answer
194 views

I'm trying to understand how to shorten regex

I'm trying to list all directories that are 1GB or larger. I know I could use ncdu, but at the moment, I'm just trying to understand how to shorten regex... I found this command, du -h . | grep '[0-9\....
Marslander's user avatar
-1 votes
2 answers
95 views

SED - Generate line only if match some words in OTHER LINE [duplicate]

Assume I have 2 files in a folder ... product: Nike New Awesome Running Shoe price: 123 color: black ... ... product: Nike New Awesome Salloon Soccer Shoe price: 123 color: black ... I need to ...
Adriano d'Avila Borges's user avatar
-1 votes
5 answers
161 views

SED - Generate line using some content of other line

I have some files in a folder Each file has this structure: ... product: Nike New Awesome Shoe price: 123 color: black ... I need to accomplish bellow scenario using single SED command, in all files ...
Adriano d'Avila Borges's user avatar
0 votes
1 answer
1k views

sed + remove line with word match and only if comment appears in beginning of line

delete lines with word match is easy for example when we want to delete the line that match the word - max.connections sed '/max.connections/d' /home/conf.txt but how to delete the match lines as ...
yael's user avatar
  • 13.7k
0 votes
0 answers
18 views

Remove Exact Strings From a File [duplicate]

How do I remove exact strings using sed, tr or awk {98406c4acbf0f57b3ccbc923a6d507f422d9bd8656398f53433e}HTTP/1.0 200 OK What I want to remove is HTTP/1.0 200 OK I tried to do sed but there is a ...
iis2h's user avatar
  • 21
1 vote
1 answer
4k views

find all file extension recursively from directory and copy all extension files to single directory [duplicate]

I have directory with sub-dir where it has multiple extensions file. I would like to copy all ext files to single directory "scan". Tried running following cmd but doesnt work out: find . -...
Ankur's user avatar
  • 11
0 votes
4 answers
2k views

How to extract numbers (digits only) from other words in text with bash

Using Bash, I want to display the number of lines that contain at least one number (a number is only made of one or several digits) in an arbitrary text. I also want to display detected numbers one ...
NISHU SAINI's user avatar
0 votes
1 answer
665 views

Parse audit log commands as a complete command with arguments

I have audit logs that looks as follows: type=CWD msg=audit(1613110144.560:260397): cwd="/" type=PATH msg=audit(1613110144.560:260397): item=0 name="/usr/bin/sed" inode=393388 dev=...
Anthony Bell's user avatar
0 votes
1 answer
42 views

Moving group of files to another directory using the command "rename" with regular expressions

I have some markdown files that I want to move to a different directory called "newDirectory2" within "newDirectory1". These files contain the string "abc" or "ABC&...
Baern Ungart's user avatar
-2 votes
1 answer
2k views

bash + Compare Strings with regex

in my bash script I want to verify if string is a disk so I did the following example if [[ $disk =~ sd{a..z} ]];then echo "we found a disk - $disk . . . . fi but actually the expression not ...
yael's user avatar
  • 13.7k
0 votes
1 answer
32 views

Proper Syntax for writing all output of a command using stdin, not just the output of the command

I am trying to send the output of a curl request to a file using regular-expression. curl -k -v -x x.x.x.x:x https://repo.nagios.com/nagios/7/repodata/repomd.xml > curl1 Using the above syntax only ...
nullnv0id's user avatar
  • 195
0 votes
1 answer
1k views

How to download file by wget when file is named partially

here is the way how to download weel file by wget and copy it to /home/wheel.whl wget -q http://$REPO_SERVER/WHL/wheel-0.34.2-py2.py3-none-any.whl -O /home/wheel.whl the problem is when changing the ...
user avatar
2 votes
2 answers
2k views

bash + match regexes for both different hostnames

In my bash script I identify the machine name - kafka01 or kafka02 or kafka03 with the following regular expression bash code if [[ $(hostname -s) =~ ^kafka[[:digit:]] ]] then /tmp/run.sh fi Example ...
user avatar
1 vote
1 answer
427 views

Sort files in directories based on filename

I have > 35,000 scanned diapositives from a scientific archive in one directory. (Fortunately, the filenames are rather uniformly formatted: {year}-{place}-{film-#}-{photo-#} OR {year}-{year}-{...
Beres's user avatar
  • 53
0 votes
2 answers
326 views

How to filter PID from Linux SSH security logs?

Aug 12 01:30:26 server.example.com sshd[19486]: Failed password for root from X.X.X.X port 50528 ssh2 Aug 12 01:30:26 server.example.com sshd[19486]: Received disconnect from X.X.X.X port 50528:11: ...
Bruce Malaudzi's user avatar
0 votes
2 answers
1k views

Regex lowercase script validation

I am working on a homework assignment to validate whether an entered string is in all lowercase letters. Here is the basic script that we are provided. Here is the line I need to change. if [[ "$...
Brian Majurinen's user avatar
5 votes
4 answers
2k views

if with regex in bash code

In bash I did the following. This if expression will evaluate to true if the Redhat version is 7.5 or 7.6. if [[ ` cat /etc/redhat-release | awk '{print $7}' ` == "7.5" ]] || [[ ` cat /etc/redhat-...
yael's user avatar
  • 13.7k
0 votes
2 answers
2k views

And operation and case insensitivity in awk regular expression?

I'm trying to match filenames that contain two text patterns but the matching process should ignore case. Neither of the following regular expressions work: Setting the awk variable 'IGNORECASE' to a ...
bit's user avatar
  • 1,142
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
1 vote
3 answers
3k views

How to test if a folder exists using regular expression in Bash?

as all know we can check easily if folder exists by the following bash command [[ -d /opt/presto-server ]] && echo folder exist but when we have folder as /opt/presto-server-32.34 then how ...
yael's user avatar
  • 13.7k
0 votes
3 answers
1k views

how to check if FQDN host-name is with only small letters

we want to check the hostname on machines the rule should be like this: each hostname must be only with small letters each hostname is FQDN we try this hostname=master01.nassa.com [[ $hostname =~ ^...
yael's user avatar
  • 13.7k
6 votes
4 answers
9k views

BASH: Check in /etc/shadow if user password is locked

Objective: Check in /etc/shadow if user password is locked, i.e. if the first character in the 2nd field in /etc/shadow, which contains the user's hashed password, is an exclamation mark ('!') ...
DavDav's user avatar
  • 517
4 votes
3 answers
784 views

bash + verify name by regular expression

Why does the following regular expression print valid, when the name is hdpworker01? name=hdpworker01 [[ $name =~ worker[[:digit:]] ]] && echo valid What I try to do is print valid only if ...
yael's user avatar
  • 13.7k
1 vote
4 answers
361 views

How to match version number from output

With the following yum info call we can capture the installed version of ambari-metrics-monitor yum info ambari-metrics-monitor| grep -i version |head -1 Version : 2.6.1.0 and to verify from ...
yael's user avatar
  • 13.7k
6 votes
4 answers
5k views

how to remove files that could be with lower/upper case

how to remove files that could be with lower/upper case for example, the file_name could be: STOCK.Repo or Stock.REPO or stOCK.repo or stock.repo ... etc I would run: rm -f $file_name the ...
yael's user avatar
  • 13.7k
0 votes
4 answers
6k views

regular expression to capture the folder name with specfic structure

what is the regular expression to capture the folder name with this structure x.x.x.x-x ( x - integer number ) ls /usr/hdp | ..... 2.6.0.3-8 current HG_MASTER 2.4.3 34.1 45-995 expected output ...
jango's user avatar
  • 423
-2 votes
1 answer
88 views

bash + how to capture the first/seconf/thired field [closed]

we can easily to capture the first field by awk as this syntax capture=` echo 1 2 3 | awk '{print $1}' ` we can easily to capture the sec field by awk as this syntax , and so on capture=` echo 1 ...
jango's user avatar
  • 423
7 votes
2 answers
32k views

bash - case-insensitive matching of variable

This syntax prints "linux" when variable equals "no": [[ $LINUX_CONF = no ]] && echo "linux" How would I use regular expressions (or similar) in order to make the comparison case ...
yael's user avatar
  • 13.7k
3 votes
2 answers
5k views

validate file content with bash Regular Expressions

How to validate the following file content? That should be include single integer/float number by bash Regular Expression or any other idea with awk/sed. example: cat /var/VERSION/...
jango's user avatar
  • 423
-2 votes
2 answers
1k views

bash + while loop with regular expression [closed]

The following loop is looping when number is less than 1 or greater than 45 but it fails when the answer includes special characters such as [ % & * # ] etc What can I change in the code in ...
yael's user avatar
  • 13.7k
1 vote
2 answers
809 views

Find works fine in command line, but won't work in script

I am trying to write a script on a Debian Jessie host. I am having an issue with trying to run the following command (with a twist) in a script: find ~/* -path ~/FileSniper* \ -prune -o \ -type f \( ...
Martin's user avatar
  • 11
-3 votes
1 answer
52 views

Regexp pattern - is it correct and what is its purpose? [closed]

Is this pattern correct? logPattern = ^NAME.log(-\d+)?$ What is the purpose of this?
José Luis's user avatar
0 votes
2 answers
2k views

Grep for regex in basename but return wholename

So say I have a list of files in a text file: ... /foo/barfoo /bar/foo/foobar /foobar/bar/foo ... I have a script that will search through this text file and, much like the locate command, I want to ...
user120161's user avatar
4 votes
2 answers
2k views

Print repeating pattern

I have a marathon file from which I want to print the names of the runners, who have made multiple runs. Something like: M, 2:08:58.0, John Lukas, USA, 1997-07-25, Paris, France F, 2:15:04:0, Abebbe ...
Highlights Factory's user avatar
12 votes
4 answers
58k views

Regular Expression for finding double characters in Bash

I am looking for a regular expression that finds all occurences of double characters in a text, a listing, etc. on the command line (Bash). Main Question: Is there a simple way to look for sequences ...
erch's user avatar
  • 5,120
13 votes
2 answers
45k views

Regular expression problem(s) in Bash: [^negate] doesn't seem to work

When I execute ls /directory | grep '[^term]' in Bash I get a regular listing, as if the grep command is ignored somehow. I tried the same thing with egrep, I tried to use it with double and single ...
erch's user avatar
  • 5,120
3 votes
2 answers
1k views

perl regex replacing globally when global not selected

I'm using Ubuntu 11.04 and wrote a small script that searches within text files for certain "tokens" and replaces with some a prewritten snippet from a template file of the same name. The text files ...
not a good scriptwriter's user avatar