All Questions

Filter by
Sorted by
Tagged with
0 votes
2 answers
32 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: ...
user avatar
  • 3
0 votes
1 answer
55 views

Passing arguments into a glob pattern within a script

I have a script called get_numbers.sh, which I want to use to extract data from .pdf files labelled sequentially by date, using pdfgrep. Let me simplify my problem to what I believe are its essentials:...
user avatar
1 vote
2 answers
76 views

How to introduce support for command line options in a script that is written to use positional arguments?

I have a script that is currently used with positional arguments, like this: ./script.sh fname lname address I want to also support ordinary command line options when I call this script, so that I ...
user avatar
  • 113
0 votes
1 answer
31 views

how to use xargs to extract a list of names from IRC

Using the finch IRC client, I copy/pasted a list of names to names.txt for processing. Basically, the names are seperated by spaces. Many of the names will have special characters like "/" ...
user avatar
1 vote
1 answer
27 views

Best way to access files inside of directories with common part of dirname

the title is not self-explanatory at all, but I don't know how to formulate it correctly. I will explain with an example. I have a directory structure like this: results/ test_0_part1_x000/ ...
user avatar
  • 111
-1 votes
1 answer
35 views

Finding error in my script

I have a messy script which should get the name of the site (like https://google.com/etc): #!/bin/bash ARTIST=$(echo "$@" | grep -oP 'https:\\/\\/\\K.+?(?=.com)' | sed -e "s/\b\(.\)/\u\...
user avatar
  • 3
0 votes
1 answer
842 views

Shellscript match regex

I am trying to check if a variable matches a regex in POSIX shell. However, this seems more difficult than I thought. I am trying to check if the variable is a valid size string (e.g. 10M or 6G etc) ...
user avatar
1 vote
2 answers
168 views

Finding a string in a txt of house addresses with number ranges by passing in exact number and street names

Context I'm a postal worker (mail sorter) and am trying to write a bash script which allows me to input an exact street address and first couple letters of a street name, and have it return the ...
user avatar
1 vote
3 answers
10k views

How to get group results using grep?

How would I get this output: Found value: This order was placed for QT3000! OK? or Found value: This order was placed for QT300 or Found value: 0 using line.txt and pattern.txt as below: [nsaunders@...
user avatar
0 votes
1 answer
357 views

Grep two strings from a curl response, output them to a file on the same line

I would like to automatize a process. I have a list of IP addresses to use in a curl request: curl http://api.geoiplookup.net/?query=($ip) From curl's output, I want to grab the city and write a ...
user avatar
0 votes
1 answer
166 views

Replacing multiple lines with sed using a scriptfile (sed -f)

Based on the awesome answer found here, I'm trying to use some of these commands inside a sed scriptfile that will be called using sed -f. The file has multiple sed commands and it's been working ...
user avatar
  • 101
0 votes
1 answer
380 views

macOS bash script regular expression not working as expected

I've been out of programming for more than 10 years. I have a text file that I'm trying to read the Mpbs value for the upload and download speed. Server: Iomart - Maidenhead (id = 3839) ...
user avatar
0 votes
1 answer
51 views

How to Search XML Block and Delete the same

This is my XML. <configGroup> <type>SERVER_CONFIG</type> <configProperty id="Server48"> <configProperty> <name>Server Name</name> <...
user avatar
  • 1
2 votes
3 answers
538 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....
user avatar
  • 2,165
0 votes
1 answer
198 views

Script to remove all modules in pom.xml except the one with the highest number

Question I have a huge pom.xml from a Talend DI/ESB project, where it was possible to have multiple lines for the same module with different Talend specific versions (don't even ask for that :-( ) ...
user avatar
  • 103
6 votes
3 answers
689 views

Replace MAC address with UUID

I am looking for a way to mask the client MAC address every time it appears in a logfile before using the logfile to present data to a customer (GDPR rules). I can identify the MAC string using regex,...
user avatar
0 votes
3 answers
1k views

perl regex - How to match foobar that does not begin with (\s*//\s*)

Basically I want to find foobar on uncommented lines like: // foobar # do not match me foobar # match me otherfoobar # do not match me To match the commented lines I use this: ^(\s*//...
user avatar
  • 407
0 votes
1 answer
31 views

Trying to parse a string in BASH for [ - _ ]

I have a BASH script that allows a user to specify a jobname. Right now we except everything. We feed this jobname into another executable that can only accept the following formats: job_name, ...
user avatar
  • 43
2 votes
1 answer
1k views

Use regex for file matching, not string matching

I'm trying to figure out how to use grep to search for for a specific string, (for the sake of simplicity) say "9", and I want to search for this, again for simplicity, on all files containing the ...
user avatar
  • 23
6 votes
2 answers
3k views

How to write regexp literal in match expression?

This question is about the proper way to write regular expression literals in a match expression under bash. In zsh, the match below succeeds, as I expected: % [[ ' 123 ' =~ '^ [0-9]+ $' ]]; echo $? ...
user avatar
  • 12.7k
0 votes
2 answers
282 views

Syntax for regular expression searching for DNA codons

I have to write a script for an assignment which will take the file name as a command and output every unique 3 base codon in the file and how many times it occurs in descending order. The script has ...
user avatar
0 votes
2 answers
670 views

extract field from file using sed or awk

I have bash script to collect all hardware info but following memory info piece is missing, so this is what i am trying to do. Following command give you status of DIMM memory module, [root@Linux ~...
user avatar
  • 1,530
0 votes
1 answer
52 views

Copy files with certain extension from many nested sub-directories to a single directory and append to each copied file the name of the directory

I have a parent directory with thousands of directories within sub-directories and so on. In some of the sub-directories I have few image files. I want to copy (rsync is preferred) all of the bmp ...
user avatar
  • 23
4 votes
2 answers
11k views

One liner matching filenames with regular expressions?

I have a small script. #!/bin/bash # test for regular expressions to match... DIR="/search/path/" NAME="FOO[0-9][0-9]_<bar|dog|cat>" for FILE in `find ${DIR} -maxdepth 1 -type f -name "*\.[dD][...
user avatar
-2 votes
2 answers
2k views

sed: regex input buffer length larger than INT_MAX

I have a big file to which I am doing various operations, and this error just came up. I tried googling it but there didn't find any result with this. sed: regex input buffer length larger than ...
user avatar
  • 11
-1 votes
2 answers
108 views

Using regex in the heredocument redirect/append line, to target specific "sets" of directories

I need a way to target all sub directories under public_html which ends with .com or other TLDs like .biz or .co.il I might list, in a heredocument. This my hereoducmnet inside an pushd-popd - if-fi ...
user avatar
  • 1,712
0 votes
3 answers
1k views

awk script to list files with specified filenames

I am trying to write an awk script which have string as a pattern and want to list all file in a directory which have this pattern in their name. but I don't know how to tell my awk function to read ...
user avatar
1 vote
2 answers
6k views

How to insert text between two set patterns with sed?

I need to insert text between two set patterns in a large set of files. I need to change every line with this form: <a href="/entry/someFile"> To this: <a href="/entry/someFile.xhtml"> ...
user avatar
-2 votes
1 answer
78 views

Script to rename specific part of the filename with another file name?

Contents of folder /home/User/Desktop/DR dr_subject00001_Z.nii dr_subject00002_Z.nii dr_subject00003_Z.nii ... and so on (increments by 1 up until the number 40) Contents of folder /home/User/...
user avatar
  • 21
-2 votes
1 answer
55 views

How do i specify text in a bash script [closed]

Hi I'm building a script and i need to match text from a output file to match certain conditions but it is as if it does not look to see if it actually matches: echo $RESULT | grep -q '[a-z]&[A-...
user avatar
0 votes
1 answer
1k views

Replace all Social Security Number (SSN) digits with X's

I want a sed command that will change all the numbers in all Social Security # sequences (formatted only like this 123-45-6789 or this 123456789) to X's. Any sequence of numbers that are not formatted ...
user avatar
  • 103
1 vote
1 answer
320 views

KSH Pattern from variable does not work

Could somebody explain me why pattern in Korn shell (assigned to variable) works this way: u@h:w$ pattern='file_[0-9][0-9]' u@h:w$ ls $pattern file_01 file_02 file_03 But it doesn't work for ...
user avatar
  • 145
1 vote
1 answer
186 views

substitute at beginning of line

I want to search a pattern and insert a character at the beginning of a line using regsub in TcL. I have to use TcL only Input file mna1 x a1 vss vbn nch_svt_mac nfin=nfin_n1 l=ln1 mna2 x a2 vss vbn ...
user avatar
  • 4,370
0 votes
1 answer
109 views

regex to remove last four characters

Is there a way I could eliminate the last four characters with regex in the below one line script as I convert .wav files into .mp3 files. As of right now my single line script produces files ending ...
user avatar
  • 161
3 votes
1 answer
2k views

Regular Expression to match (not x) and y (!x & y)

I received a desktop day-to-day calendar with puzzles. One such puzzle was deciphering a quote where the letters were substituted with symbols. I used some RegExs to find longer words, then used the ...
user avatar
  • 2,289
3 votes
2 answers
322 views

Remove all but the latest backup file monthwise

I've got a directory, containing lots of weekly generated files with names like db_20130101_foo.tgz db_20130108_foo.tgz db_20130115_foo.tgz ... and so on. Over the years, the disks will get ...
user avatar
  • 438
0 votes
1 answer
163 views

Filtering Log Output on Separate Lines

I did a recursive grep in a directory to find all files that would match as follows grep -ER "match_string1|match_string2" /path/to/dir/ What I get as output is: /path/to/dir/timestamp.log:...
user avatar
1 vote
1 answer
605 views

Why does the same sed regex (after grep) fail when run in a bash script vs bash command line?

Here's the script. It is successful when I run it from the BASH prompt, but not in the script. Any ideas? When I say "fails," I mean the sed regex doesn't match anything, so there is no replaced ...
user avatar
  • 141
1 vote
5 answers
242 views

grep for text that may or may not be present

Lets say I have a file batman; robin; superman; password = ""; wonderwoman green lantern if I want to check if there is a password present, i.e there is something entered in the "" . here is an ...
user avatar
  • 2,939
16 votes
6 answers
31k views

How can I extract/parse a complete URL from a semi random string?

I'd like to have bash parse/extract a full URL (and only the url) from a random short string. Examples: bob, the address is http://www.google.com or https://foo.com/category/example.html is up ...
user avatar
  • 8,289
2 votes
1 answer
4k views

Using BASH versus ASH on Synology

The majority of my photo files have the following naming convention / format IMG_20131204_120000.JPG, showing date and time the photo was taken (iPhone/Apple naming convention). However, not all my ...
user avatar
  • 317
12 votes
2 answers
29k views

Regular expression in bash script

This is my first time bash scripting so I'm probably making an easy mistake. Basically, I'm trying to write a script that gets the groups of a user, and if they are in a certain group, it will log ...
user avatar
  • 223
3 votes
2 answers
2k views

How can I find matches with sed (or similar) for configuration parameters?

I'm pretty good at using php's preg_match (and similar) commands, and I'm also pretty good with regular expressions, but I don't do very well with sed. I have two shell scripts I'm working on and I'd ...
user avatar
  • 41.2k
3 votes
2 answers
1k views

Parse apache logs to exclude IP ranges

I need to look for some requests in a huge pile of apache logs. My only requirement is this: I need to only view the requests coming from any IP address that is NOT included in a list of 50 IP ranges ...
user avatar
10 votes
7 answers
1k views

How to merge text of alphabetic lines with the numeric lines in shell?

I Have a file that has text like this: AAAA BBBB CCCC DDDD 1234 5678 9012 3456 EEEE 7890 etc... And i want to match up the Alphabetic lines with the Numeric lines so they are like this: AAAA ...
user avatar
  • 673
10 votes
2 answers
40k views

Sed: replacing digits

I am trying to write some install scripts for when I install/upgrade Ubuntu. I'm having trouble with fixing logrotate.d: /var/log/ufw.log { rotate 7 weekly missingok notifempty compress delaycompress ...
user avatar
7 votes
5 answers
39k views

Match regex in ksh

I am looking to do something like this in KSH: if (( $var = (foo|bar)[0-9]*$ )); then print "variable matched regex" fi Is it possible at all? For the record I'm using Ksh Version M-11/16/88i ...
user avatar
  • 18.3k