1
vote
3answers
59 views

Can anyone explain why this pattern matching is not working using sed

Trying to print out specific times of logs based on recommendation from this thread from super user. I am not sure why my patterns are not being matched by sed. I have the sample date and time I am ...
1
vote
1answer
46 views

Matching only numbers that come in numerical order

I have numbers in [.] indicating the page number of an orginal printed document I am transcribing. However, the document also contains other numbers in [.] that do not correspond to page numbers. For ...
2
votes
2answers
56 views

sed: How can I replace \r\r\n?

In this question on stackoverflow it is explained how one can replace a newline character using sed. My problem is that I want to replace the character sequence \r\r\n with sed. Can somebody help me ...
1
vote
1answer
48 views

How to replace line in file with pattern with sed?

I'm reading a lot of documentation on sed, and am still stumped on my particular use case. I want to replace this line in a conf file with my own line: Replace this line: #maxmemory <bytes> ...
0
votes
3answers
28 views

Almost-flattening a directory structure

I have a bunch of directories in a structure like this: -Music -Artist1 -Album1 -Album2 -Artist2 -Album1 -Album3 -Artist3 -Album2 -Album4 All the directories will ...
1
vote
3answers
102 views

Permanently set `find` regextype

GNU find allows the use of different regex formats via the -regextype option, but as far as I can tell I have to type out -regextype <whatever> every single time which is onerous. If one wants ...
1
vote
0answers
38 views

Script to port specifc data from doc1 (notepad++) to specific place(s) in doc2

I really appreciate your help with a windows script or regex function that ports specific data from doc1 (xml in notepad++) to specific place(s) in doc2 (notepad++). I'm running win8. Thank you in ...
1
vote
2answers
60 views

Filtering input with sed (regex)

I'm having an issue with sed not returning what I expect when using a regex pattern to clean up some output from a mysql query. mysql -uroot -p -e 'SELECT `path` FROM db.media_gallery' | sed -n -r ...
2
votes
3answers
116 views

What does really mean null string?

I'm sure most of us know that when we want that some regex matches with a string at the begin of the line we must use "^" ... But, I'm trying to understand what really means "empty string at the ...
1
vote
1answer
135 views

Better way to extract a substring in bash

I have a list of mp3 files named like so: $artist/$album ($year)/$tracknum $title.mp3 Many of these tracks have incorrect or missing tags, which I am correcting through the use of id3v2 and regex ...
0
votes
1answer
118 views

Grep get everything except matching

Lets say I have a text file that says: Hello my name is agz. I am asking a question that is important. If i type: grep -v "is" /path/to/file, I should get no output because both lines have "is". ...
0
votes
0answers
84 views

How to pipe regex with ffmpeg and perl?

So I am trying to get the current frame of the conversion with this bash command: ffmpeg -i fd.mp4 fd.avi < /dev/null 2>&1 | perl -015 -e 'print <STDIN>=~/frame=(\ {3})(\d+)/' | sed ...
-1
votes
2answers
112 views

Replace all numbers following a specific string with another number using sed or awk

I have tried several things but got no luck. I have an input file that has a lot of fields like this one weight=0.123456 mixed with other fields. I want to multiply all such weights by a factor, say ...
1
vote
2answers
81 views

Finding folders only

My harddrive is in a mess, so I decided to do a cleanup. As a part of this, I want to merge all folders containing music into one. What I want to do is, look for any *.mp3's and *.aac's on my drive ...
0
votes
1answer
118 views

Bash: Grep regular expression failing to work

When using grep like so: ps aux | grep 'processname' | awk '{print $2}' The PIDs of processes withprocessname is returned. When using this: ps aux | grep '^processname' | awk '{print $2}' I'm ...
2
votes
2answers
348 views

Conditional spaces in a regular expression?

Using grep, how would I do this in one command line? I have this so far grep '\$[0-9][0-9]\.[0-9][0-9]' money.txt with various strings in the text file, but I'm having issues satisfying some of my ...
2
votes
5answers
433 views

Getting regex to match a filename

I have a script that lists a bunch of files that match a certain criteria. It outputs filenames only and there is a bunch of text that is unnecessary. An example string is: ...
1
vote
2answers
57 views

Trying to get `$FOO =~ bar|baz` to work in Bash and Zsh

I'm trying to get a simple if statement working in both Zsh and Bash but I can't find something to work with both. # this works with Zsh if [[ "$TERM_PROGRAM" =~ iTerm\|Apple_Terminal ]]; then echo ...
2
votes
2answers
296 views

Bash RegEx on OSX Vs Linux (oddities)

This is about Bash development and coding of portable Bash scripts that use RegEx. Using Bash RegEx, on a Mac, I can do this: coconut-mac$ a='bananacoconutman'; [[ "$a" =~ banana(.*?)man ]] ...
4
votes
2answers
1k views

Removing files matching a numeric range regular expression

I have a folder which has many files. Some of the data files are labelled 1, 2, 3, ..., 300 I want to remove these data files using the terminal. How do I do this? I want to do something like rm ...
1
vote
6answers
927 views

UNIX “find” command, match literal “dot”

I need files ending with ".pdf" or ".png"; here's my attempt: find /Users/robottinosino/Desktop/_PublishMe_ -type f -regex '.*[pdf|png]' this incorrectly includes files ending with "Apdf", "Zpdf", ...
5
votes
1answer
2k views

Regex for “or” of multiple words in grep

[Computer]$ grep "foo|bar" filename I understand the above command should return each line in filename where there exits "foo" or "bar". The man pages confirms | as the Regex or symbol and the code ...
1
vote
2answers
540 views

Match a line until a # ,but without the #, when parsing a file with a regex

I want to parse my sources.list to extract the list of repositories. I have: ## Some comment deb http://some.vendor.com/ubuntu precise stable deb-src http://some.vendor.com/ubuntu precise stable deb ...
11
votes
3answers
2k views

Substitution in text file **without** regular expressions

I need to substitute some text inside a text file with a replacement. Usually I would do something like sed -i 's/text/replacement/g' path/to/the/file The problem is that both text and replacement ...
1
vote
2answers
194 views

Extract URLS from code statements in JS files

All, I want to extract all URLS mentioned in code statements in all js files in a folder. For e.g. if a js file contains this piece of code: var myURL="http://yahoo.com/signup" //var ...
5
votes
3answers
7k views

How to ignore certain filenames using “find”?

One of my favorite BASH commands is: find . -name '*.*' -exec grep 'SearchString' {} /dev/null \; which searches the contents of all of the files at and below the current directory for the ...
3
votes
3answers
4k views

Delete files with regular expression

I Tried to delete files that starts with A and ends with 2 numbers but It doesn't do a thing. What I tried: rm ^A*[0..9]2$ Where am I wrong?
0
votes
1answer
471 views

How to insert thousand separator with `sed`?

I want to insert thousand separator into a number sequence with sed and this ugly RE sed -e :a -e 's/\(.*[0-9]\)\(\([0-9]\{3\}\)\(,[0-9]\{3\}\)*\(\.[0-9]*\)\)/\1,\2/;ta' [filename]. Is there a more ...
3
votes
3answers
3k views

Remove all files containing a pattern

Suppose I have a directory with files and subdirectories underneath it. Some of the files contain a pattern "^File:" in their contents. Is there some way I can use grep and a bash command to remove ...
0
votes
1answer
68 views

Searching for *.graphml files with the find utility

I am trying to find all my GRAPHML files under the current directory in bash. So I ran the following command: find . -name *.graphml And I get the error message: find: paths must precede ...
8
votes
4answers
4k views

Newlines in sed on Mac OS X

I find that \n doesn't work in sed under Mac OS X. Specifically, say I want to break the words separated by a single space into lines: # input foo bar I use, echo "foo bar" | sed 's/ /\n/' But ...
4
votes
2answers
1k views

How to rename all files and directories in current folder?

I have a directory structure like this: ./ whatever/ foos_whatever.ext something/ foo/ 1.ext 2.ext another/ foo.ext I want to rename all files and directories that ...
1
vote
2answers
518 views

Finding files in linux based on regex, with multiple alternatives

Let's say I have a list of strings. I want to find files with filenames starting with these string. Example, Strings: filename.could.start.with.this.restoffilename ...
3
votes
2answers
2k views

How to get list of files that don't match patterns in bash?

I have a file with joker character patterns: ./include/* ./src/* etc. From the current directory I would like to recursively get the list of files that do not match these patterns.
8
votes
7answers
5k views

How do I copy file named starting with a dot?

I am trying to copy all files under directory A to directory B. All files under directory A are starting with dot, for example: A/.a A/.b A/.c which I found if I use: cp A/* B, always get error: ...
0
votes
2answers
582 views

BASH history manipulation: search replace

There is a really handy parameter/variable expansion feature in BASH that I don't see for history. I've checked man pages for history and for BASH itself. Not there ...maybe I missed it. Example: I ...
0
votes
1answer
59 views

How to show regexp

I want to show what stands behind a regexp, for example, I want to print all chars covered by [A-z] in the bash.
3
votes
2answers
4k views

“ls” or regex is case insensitive?

In bash, I tried ls [a-z]* and expected to list all the files with filename starts with small case alphabet. But why the files with name starts with big case alphabet are also shown? >ls ...
1
vote
2answers
351 views

cut text from each line in a txt file

i have a text file where each line looks like this: <img border=0 width=555 height=555 src=http://websitelinkimagelinkhere> each line is like that for like 1500 lines, i want to sort of ...
1
vote
2answers
320 views

How to show regexp parts of text

I've lots of files which lines looks like lotsofblah/XY##_####_morefoo where # is a number. Now i want to show only the parts YZ##_#### in the bash, each in a new line of course.
2
votes
3answers
397 views

How to use “rm” to remove files with a “:” in them?

I am using Ubuntu 10.04, and I have a directory with a bunch of files. We changed the naming scheme of the files a while ago, and now I want to delete all the old ones. New Name scheme: ...
4
votes
4answers
404 views

deleting folders in linux bash

i'm trying to delete in gnu/linux all folders inside another folder that start with a "." (dot), for that i'm using the find utility, this is what i have: find . -iname ^\..* -exec rm -rf {} \; but ...
0
votes
1answer
4k views

Hot to remove special chars from filenames and rename them in a directory?

This is what I have so far. #!/bin/bash pushd DirectoryName for file in *.csv; do #echo $file filename=${file%.*} file_clean=${filename//[ ()$+&\.\-\'\,]/_} final= ...
5
votes
2answers
14k views

How to delete files on the command line with regular expressions?

Lets say I have 20 files named FOOXX, where XX is the number of the file, eg 01, 02 etc. At the moment, if I want to delete all files lower than the number 10, this is easy and I just use a wildcard, ...