3
votes
3answers
53 views

Sed replace only in even numbered lines of a file when replace commands are written in a file

I have all the replace commands in a file (say replace.sed) and i use it with -f flag of sed (sed -f replace.sed InputFile). But now i ran into a condition where i need to apply these replace rules ...
2
votes
1answer
36 views

find using regexp and echo matches

I have about 50 users in /home/ directory and I have cloned a git repository to everyone: Executed at /home/ as root user: find . -maxdepth 1 -type d ! -name . -prune -exec git clone ...
3
votes
2answers
464 views

How to comment out multiple line matching a regex using sed or awk

I have a file that contains this: [...] location /static { ... multiple lines ... } [...] location /static/ { ... multiple lines ... } [...] And I want to get: [...] # ...
1
vote
1answer
27 views

Is it possible to sed -i from a text file to another text file?

I'm coding a shell script on my Debian box and there's a line on the script that needs to delete some emails from a textfile that is full of emails, like this: sed -i ...
5
votes
1answer
152 views

Non-greedy regular expression to convert command tags

Background Consider the following text: There are three types of font families: serif, sans serif, and teletype. To switch between these families, use <cmd>rm</cmd> for serif, ...
0
votes
2answers
294 views

Regex for unix paths

What would be the correct perl regex for detecting only Unix paths? ./dir1/dir2/file.ext - invalid ./dir1/dir2/ - valid ./dir1/dir2 - valid
1
vote
4answers
1k views

Batch renaming of files using regular expression in Unix

I have several thousand files of the form: [8-digit number]_[number I want]_S60491_I129111.dcm. I wish to remove everything except the number I want, and use that as its name. In Ruby, I can get to ...
0
votes
3answers
238 views

Replacing quotes in a file

I have a large number of large semicolon-separated data files. All string fields are surrounded by double quotes. In some of the files, there are extra quotes in the string fields, which messes up the ...
2
votes
1answer
289 views

Input field separator in awk

I have many large data files. The delimiter between the fields is a semicolon. However, I have found that there are semicolons in some of the fields, so I cannot simply use the semicolon as a field ...
3
votes
1answer
4k views

How to set line length limit when using grep (Filter result by line length)?

The use case is that I am searching for a particular CSS attribute in a directory of HTML/CSS/JS files (including sub-directories). Some one-liner JS libraries also have the CSS attribute that I'm ...
3
votes
3answers
164 views

unix command to verify span of word in text

What unix command(s) can I use to determine the line span that a word appears in text? The "span" being equal to the line number of the last instance of a word minus the line number of the first ...
1
vote
6answers
1k 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
82 views

sanity check file to produce binary answer

What Unix command(s) can I use to determine the existence of each of several words and the non-existence of each of several words which will produce a binary answer? For example: I want to be sure ...
6
votes
1answer
3k 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 ...
4
votes
3answers
6k 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?
4
votes
2answers
2k views

List directories containing files that match a regular expression

I would like to set up a simple filtering system on my FreeBSD server that allows me to create arbitrary "views" of directories. For instance, I'd like to be able to list all directories that match ...
15
votes
2answers
10k views

Counting total number of matches with grep instead of just how many lines match

Does grep offer a way to count the total number of matches it makes? The -c option only returns the number of lines that matched the regex, but in this case I have multiple matches per line.
0
votes
2answers
482 views

File matching pattern on command line?

Can someone help me with a relatively complex command-line file matching pattern? I've got files in a directory as follows: 1.png 1_thumb.png 1-1.png 1-1_thumb.png 1-2.png 1-2_thumb.png 2.png ...
3
votes
2answers
77 views

Unix tool to show files where the content does not match

If I want to see a list of files which contain the word 'FOO' I can use fgrep -l 'FOO' * but what if I want to see all of the files which do not contain the word FOO? I can't use fgrep -vl 'FOO' ...
0
votes
4answers
2k views

Unix: Search and replace in file names

Using sed, I can search and replace text in a file. Is there a way I can do search and replace of filenames? For example if I have a bunch of files in a folder with names like these: foo01 foo02 ...
8
votes
5answers
3k views

How is \$ being interpreted by grep?

When I write $ grep \$ then whatever I type on terminal, is matched and printed on terminal. How is \$ being interpreted?