Tagged Questions
-1
votes
2answers
53 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
67 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
78 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
70 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
202 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
50 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
141 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 ]] ...
3
votes
2answers
328 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
484 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", ...
2
votes
1answer
390 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 ...
0
votes
2answers
272 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 ...
8
votes
3answers
726 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
138 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 ...
1
vote
3answers
2k 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 ...
1
vote
3answers
1k 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
281 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 ...
2
votes
3answers
1k 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
61 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 ...
3
votes
4answers
2k 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 ...
0
votes
1answer
110 views
Unix find behavior with spaced phrases between wildcards? [closed]
I am using a find command like
find . -name "*<phrase>*.ext"
This command works fine, when phrase has no spaces. However, if I try something like
find . -name "*A phrase in the file ...
1
vote
2answers
373 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
...
2
votes
2answers
1k 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.
6
votes
7answers
3k 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
497 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
3k 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
324 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
252 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
339 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
330 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
3k 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= ...
2
votes
2answers
8k 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, ...