3
votes
1answer
27 views

Merging text files based on their filename

I have hundred of files with the following format: 2013_01_19_xyxyxyx.txt 2013_01_19_xyxyxyx.txt 2014_03_21_xyxyxyx.txt 2014_03_21_zxzxzxz.txt 2014_03_22_abababa.txt 2014_03_22_cbcbcbc.txt etc. I ...
0
votes
4answers
55 views

bash event not found trying to match and exclude parenthesis in grep

In a very long line I'll summarize with: (foo),(bar,baz(word,right),(end) I want to print only: (bar,baz(word,right To match the second parenthesis, I exclude the word that follows the ...
1
vote
1answer
76 views

How to get the JSON STRING from the given string

I have a string given below. I just need to get the first accountHeader (bolded) JSON string, I tried everything.. It didn't work. Can you help me to get the data? <START ...
3
votes
1answer
115 views

Why does grep treat '[D]ebug' string differently?

I've created simple text file named "T" to test the unusual behavior of grep: 1 Debug 2 debug 3 determined 4 Determined Tried different syntax: $ grep De T 1 Debug ...
4
votes
2answers
60 views

Why sed prints first string from file even if it's failed to find matching groups

I'm trying to write sed expression which will extract matching groups from file. E.g. I have .cue sheet and I want to extract it's genre tag. It has following format: $ cat file.cue | grep GENRE REM ...
1
vote
2answers
677 views

Differing outputs of the commands “ls .*” and “ls *.”

The command ls .* when run gives as output the following : All the files in the current directory starting with a . (hidden files) All the files in the hidden directories present in the ...
6
votes
2answers
186 views

Why two almost idetical grep commands return different output: w/o and with filename

I have 2 almost identical greps: [Alex@localhost tmp]$ grep /bin/bash /etc/passwd root:x:0:0:root:/root:/bin/bash AlexL:x:500:500::/home/AlexL:/bin/bash user1:x:501:501:user1 ...
1
vote
2answers
138 views

What does this regex mean?

I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex sed 's/$'"/`echo \\\r`/" ...
1
vote
3answers
177 views

Escaping * with Regular Expressions and Grep

I have a file that has unique lines that start with 2 stars (**). However when I run a grep command for grep \*\* fileName I get all of the lines in the file. This is very unusual, and what I ...
1
vote
1answer
73 views

What are the commands that you can use in the beginning of a sed command?

I initially learned to do sed search and replace like so: sed -e 's/<stuff>/<replacement>/' However I recently learned that these will do something different based on what command ...
3
votes
1answer
73 views

find utility does not recognize bracket notation

I've two files in the current folder: submitWeb.m submit.m the following find does not show the two files: find . -regex .*submit\(Web\)?\.m But the above regex expression works fine in ...
1
vote
3answers
378 views

Why is this Bash command using regex not replacing my brackets?

I have this command to go through all my files in my Music directory, and all subdirectories, and replace any square brackets in the file name with rounded brackets: find /home/Music/ -depth -name "* ...
3
votes
5answers
201 views

Regex match in CLI

Is there something like a logical for the cli? I want to achieve this mv -t newfolder *.(png|jpg) so that alls jpg and png files are moved into newfolder. I know it could be done with mv -t ...
1
vote
2answers
281 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 ...
2
votes
2answers
421 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 ...
2
votes
3answers
435 views

Find word in sentence with Bourne Shell (sh)

I'm trying to determine if a particular word appears in a sentence using Bourne Shell (sh). For example: #!/bin/bash INPUT='Lorem ipsum dolor sit amet.' if [[ "$INPUT" == *dolor* ]] then echo ...
1
vote
1answer
559 views

Regular expression how to get value in shell script?

I have to write a shell script to get value from a string, something like: string="abcdef" pathName How can I use grep command with the use of regular expression to get "pathName"?
1
vote
4answers
476 views

Stripping all vowels but the first from a set of strings

I have a string comprised of multiple substrings, separated by underscores. For example: AbcdAEfd_hEgdgE_AbAAAAA. I need to remove all vowels except the first from each substring. So: AbcdAEfd -> ...
1
vote
2answers
458 views

Weird zsh grep -P behaviour

I connect to server with PuTTY from Windows. I have a long yet not touched (I suppose) by hands of local admin config: $ cat /opt/jira/.subversion/config ... ### must be enabled, which is ...
13
votes
5answers
743 views

How to remove the (1) from filenames using the find command

I recently converted all of my FLAC files to a lower sampling rate of 44.1 kHz and bit depth of 24 bits (because iPhone/iPod don't support anything above that) using XLD on my Mac OS 10.7 (Lion). ...
2
votes
2answers
325 views

Detect pattern repetition in a file

I want to make sure a file follows the following pattern: ... ... ... foo ... foo_KO ... ... ... bar ... ... ... ... bar_KO ... The file is extremely long, so, in other words, I want to make sure ...
5
votes
4answers
1k views

Recursively rename subdirectories that match a regex

I have a media server with a folder called Series. (/media/Expansion2/Series/) In it, I have (surprise!) TV series. These are just the show names, e.g., /media/Expansion2/Series/The Big Bang Theory/ ...
21
votes
4answers
39k views

How do I grep for multiple patterns?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
2
votes
1answer
241 views

Delete repeated words between brackets inline

Our input looks something like 2012-04-17 [GBPGBP] 2012-04-13 [GBP GBP] 2012-04-13 [GBP] 2012-04-11 [GBPGBP] 2012-04-11 [GBP GBP] 2012-04-10 [GBPGBP] 2012-04-06 [GBP GBP GBP] 2012-04-17 ...
3
votes
1answer
192 views

Character classes: construct my own

I want to construct my own character class in a script, then modify (and use) it, for example: [:myclass:] contains a, *, \n (as linefeed) and [WHITESPACE]. I want to add all characters to ...
2
votes
1answer
488 views

remove trailing zeros in awk not working. syntax error

regex = "\\.*0+$"; subst = ""; system("echo "id "| awk '{sub(\\.*0+$," subst"); print}'"); It is giving the following error: awk: cmd. line:1: {sub(\.*0+$,); print} awk: cmd. line:1: ^ ...
2
votes
4answers
2k views

How to insert the content of a file into another file (if regexp) in shell/perl

File1 Contents: line1-file1 "1" line2-file1 "2" line3-file1 "3" line4-file1 "4" File2 Contents: line1-file2 "25" line2-file2 "24" Pointer-file2 "23" ...
3
votes
3answers
618 views

Extracting text from a text file in bash

I have a large text file that is all one line. In the text are several sections that looks like foo=12345 and I need to extract them all as separate lines, ignoring the rest of the file. For ...
5
votes
2answers
1k views

Number of backslashes needed for escaping regex backslash on the command-line

I recently had trouble with some regex on the command-line, and found that for matching a backslash, different numbers of characters can be used. This number depends on the quoting used for the regex ...
3
votes
1answer
4k views

grep and escaping a dollar sign

I want to know which files have the string $Id$. grep \$Id\$ my_dir/mylist_of_files returns 0 occurrences. I discovered that I have to use grep \$Id$ my_dir/mylist_of_files Then I see that the ...
3
votes
2answers
552 views

Replace a substring of filenames in a directory

There exists a directory, which includes several levels of sub-directories. Under these directories, there are a set of files whose names include a common word, e.g, .cc. How can I replace the .cc ...
3
votes
3answers
2k views

In a regular expression, which characters need escaping?

In general, which characters in a regular expression need escaping? For example, the following is not syntactically correct: echo '[]' | grep '[]' grep: Unmatched [ or [^ This, however, is ...
2
votes
3answers
116 views

expr help - managing strings

I need to take text like this: A234321=http://www.google..... a normal URL And pull out only the URL, getting rid of the first part. I think I can use expr to do it, but I can't figure out the ...
2
votes
3answers
567 views

regexp in ksh for extensions tgz, tar.tgz

I'm trying to get a regexp (in ksh) to identify files with only the following extensions: tgz, tar.gz, TGZ and TAR.GZ. I tried several but can't get them to work. I'm using this regexp to select only ...
1
vote
2answers
124 views

In-place substitution for lines matching some pattern in a given set of files

Following on from my previous question: Remove slashes/parent paths from filenames inside CSS and Javascript content I arrived at the following command which replaces any filenames in these ...
2
votes
1answer
1k views

Grep - ^(\s*$) vs ^\s*$

I want to search for a field that only has spaces. When counting, this two commands gave me different results: grep "^\s*$" -E -c grep "^(\s*$)" -E -c Another thing. What is the correct way to say ...
5
votes
2answers
1k views

Print specific Exif image data values with exiv2

How do I print the image Exif date with a tool like exiv2? My goal is to write the image year and month into separate variables. Do I really have to parse the output with regex or is there a ...