Regular expressions are a means of matching a pattern of characters within a string.

learn more… | top users | synonyms (1)

2
votes
1answer
105 views

csplit not obeying backslash r \r as carriage return

I have a file with \r\n line endings (CRLF carriage return line feed). This command works: $ csplit --silent --prefix=email-emailbad.txt- \ --digits=3 emailbad.txt '/^\.^M/'+1 '{*}' This ...
2
votes
1answer
472 views

Expand regex on multiple lines in Vim

I am working on removing comments from a C source file. Let's focus on multiline comments /* ... */ and ignore the inline ones (//) The following command seems to work with (solaris) sed: ...
2
votes
3answers
872 views

How to cut the output to only gather the filename and get-parameter?

I have multiple files with multiple links that are formatted like this: <a href="http://example.com/fnord.layername.html?parameter=FOO-_-BAR-_-FNORD" class="poit"> <img ... /> ...
2
votes
3answers
681 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 ...
2
votes
2answers
484 views

parsing through log file and printing out regex backreferences

I want to parse my /var/log/maillog to print out the email addresses in "from=<>" and "to=<>" (mainly to do a quick check for false positives in the DNS RBLs that I've configured) A maillog ...
2
votes
1answer
2k 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 ...
2
votes
1answer
71 views

To write this Pseudocode with Regex

I am doing a Makefile which I run regularly by Crontab every day at 0230 crontab -e; 30 2 * * * /bin/thePseudocode Python-like Pseudocode directories = ["Cardiology", "Rheumatology", "Surgery"] ...
2
votes
3answers
59 views

bash: regular expressions in if expression

In my script on my ubuntu machine I declare a string like this: DEBUG_PACKAGE_LIST=$(apt-cache search dbg | awk '{ print $1 }' | grep -e "-dbg") For you to help you understand my problem here is ...
2
votes
1answer
59 views

How to match a particular form of optional sequence from a manual synopsis, including variations?

In this Q&A there is a reference to the manpages synopses being based "loosely" on the Extended Backus–Naur Form of metasyntax notation. It's interesting and serves as background. That being said, ...
2
votes
1answer
156 views

How to perform a multiline grep across multiple files?

I'm trying to grab this pattern wherever it occurs in multiple log files (Note:these patterns can vary greatly in size, i.e. the amount of Blahs): Found an txt File Blah Blah 10019874 ...
2
votes
2answers
53 views

procmail recipe with a regex doesn't work

In my ~/.procmailrc I have the following lines: :0 \* ^Subject:.*(O|o)pen( \|)(S|s)(onic|urge) $MAILDIR/OpenSurge/ As you see, I would like to put any mail containing “Open Surge” (or any variant ...
2
votes
1answer
148 views

Using regular experision in “rpl” command

I need to replace text in lots of files. I'm using rpl for this purpose, but I can't find any way to make it use regular expressions. Can rpl use "regex"? how? Edit: I'm using rpl 1.5.2 from Ubuntu ...
2
votes
2answers
327 views

rsyslog: make %syslogtag% equal length

I have rsyslog configured to log in the following format: $template long-iso,"%$NOW% %timereported:8:15% %syslogtag% %msg%\n" which produces logs like this one: 2013-12-14 15:59:39 ...
2
votes
1answer
1k 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 ...
2
votes
1answer
169 views

Regex to find NFS filesystems that aren't being mounted with nosuid, except for ones with special needs

I have a script that runs the command mount -v 2>/some/file, which I then parse with another script using the following regex: ^.*[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).* The ...
2
votes
4answers
97 views

Alternative regex for {}

I am trying to replace all of this line, but the numbers: looktype="123" so only the numbers show up. Is this possible in any easy way? {sub ("look type=\"[0-9]{0,3}", "TEST")} I am trying this ...
2
votes
1answer
151 views

How to negate a regex inside another regex

That is, given a POSIX regex X, what POSIX regex is the complementary of X? (in a more detailed way: how to get regex X' that matches all strings that are not matched by X, but doesn't match any ...
2
votes
2answers
503 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
4answers
805 views

Change currency format to generic number using sed

I am working on a large csv file with all coma separated entries. The entire document is composed of plain numbers, except for a few columns reflecting currencies that are formatted as text. For ...
2
votes
1answer
300 views

Why doesnt ctrl+d work with this?

I wanted a simple way to process text in my clipboard without having to create a file. I tried using the following line: awk '{print $1}' <(cat) but I couldn't send cat the EOF character using ...
2
votes
2answers
2k views

regex replace text in xml file within node from the command line

I have an XML file and I would like to replace everything that is between the open and closing tag within multiple instances of the g:gtin node with nothing. Is this possible from the command line, ...
2
votes
1answer
1k views

Match one part of a regular expression in a Kwrite find-and-replace regex

Among the joys of KDE, Kwrite is surely noteworthy. Having regular expression support built in by default into text editor is probably one of the top 10 best ideas of all time. Since I often need to ...
2
votes
2answers
288 views

perl regex replacing globally when global not selected

I'm using Ubuntu 11.04 and wrote a small script that searches within text files for certain "tokens" and replaces with some a prewritten snippet from a template file of the same name. The text files ...
2
votes
2answers
22 views

Match from current line until a line that doesn't match a pattern

I really tried searching but could not find anything (it's hard to know what exactly to search for). I know how to do this with sed: print from current line until the line that matches SOMETHING: ...
2
votes
1answer
1k views

lftp exclude syntax confusion

I am confused with the syntax description given for lftp from their website: -x RX, --exclude=RX exclude matching files -X GP, --exclude-glob=GP exclude matching files How ...
2
votes
1answer
255 views

Aptitude regex engine

I was trying to lookup the versions of libdb in the debian archives with something like that: $ aptitude search '~S~ndev$(~nlibdb~(\d~|-~)!~v~rnative)' which didn't work as expected so I changed ...
2
votes
4answers
2k views

Change filename from lowercase to uppercase recursively

I have 1,000,000 files in some folders and subfolders. I want to rename them from lowercase to uppercase using shell commands. I don't want to modify the extension. only filename part. I have found ...
2
votes
4answers
714 views

regex to match identifiers without double _

I want a regex to match identifiers consisting of letters, digits and _, without double underscores. My current attempt: ^(?!_)(?!.*?_$)[a-zA-Z][a-zA-Z0-9_]+$ Example: Abdfsdfsdf__ 1B2345_ ...
2
votes
2answers
941 views

Regex for phrase matching with case statement in ksh

I am trying to start or stop a service on AIX in ksh. I am trying to start to build in fool proofing for checking things like if the services is already down, etc. Here is my script #!/bin/ksh ...
2
votes
2answers
2k views

Replace the shortest match of a string pattern

I have this string: update mytable set mycol=myvalue where mycol=yourvalue; I need to convert it to: insert into mytemp select * from mytable where mycol=youvalue; I can accomplish it like this ...
2
votes
1answer
650 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
1answer
1k views

How to block the Google Analytics Script using Privoxy

Related subject: Privoxy: blocking twitter, facebook and google outside of their domains + HTTPS Never mind what rule I am adding to the default.filter file, I don't make it to block these scripts. ...
2
votes
2answers
391 views

lookbehind and using it with grep in Vi?

Trying to get into Vi (not Vim), after learning Vim. Vim has a lookabehind like /\(Not this\)\@<!$, how to do it in Vi? If I want to search recurvively down directory in Vim, I could do :vimgrep ...
2
votes
3answers
205 views

Reverse match in sed, replace opposite of what was found

Say I have this output from my syslog, precalculated src_hash => 20 bytes @ 0x7f811c001e20 A6 2D E5 CD 2A BA F0 42 56 66 19 D4 61 1A E3 A0 .-..*..BVf..a... C7 5E 5F 77 ...
2
votes
2answers
400 views

Regular expressions with ExpectJ

I've been used the ExpectJ Java library to automate some jobs on a Linux server, however now I need to automate a job that sends a different text response for each execution. Here is the output: Last ...
1
vote
5answers
5k views

(Mac Terminal) sed to parse JSON … what am I doing wrong?

In Mac Terminal, I'm trying to parse the "name" out of this JSON response: {"created_at":"2012-08-27T20:04:27Z","deleted_at":null,"id":21462840,"item_type":"video","name":"CastingBy-v12 ...
1
vote
5answers
118 views

Extract one occurrence of a pattern from file

I have large file containing logs similar to one shown below. I would like to find all transactions(TR#) that were affected with the error. I need to extract one occurrence of each TR# ID. How could ...
1
vote
3answers
167 views

Check some property for every line of a file

I have several (427 to be precise) text files with a million lines each containing 31 numbers separated be spaces (possible double spaces). However there might be some data corruption and there may be ...
1
vote
4answers
2k views

Can tr work with regex?

I have a file like this: AAAA BBBB CCCC DDDD etc Words in separate lines. I want to add them quotes using tr. So I tried the following: 1) To add a quote in the start of each word ...
1
vote
2answers
97 views

How can I reformat tabular data using AWK?

I have a file contain following output. ora.abc.db 1 ONLINE ONLINE serverA Open 2 ONLINE ONLINE serverB Open ora.xyz.db 1 ...
1
vote
2answers
135 views

Why `rename` behaves differently whenever I use full path instead current path?

Ok, I'm answering a question where the OP have several repositories in Ubuntu that might be causing a problem installing unrelated software. I recommend disabling the PPA's using a single liner rename ...
1
vote
2answers
61 views

What does this regex mean? <!--.*?-->

What does this regex do? <!--.*?-->
1
vote
3answers
56 views

Stuck in separating chars into strings in my approach. Found a working approach but can not understand it

I am trying to figure out how to break a string to be on character per line. I.e ahebhaaa to be: a h e b h a a a I tried: $ echo ahebhaaa | sed 's/\(.\)\(.\)/\1\n\2/g' I.e. my ...
1
vote
3answers
3k views

Print lines where first field has only four characters using regex in awk?

John Goldenrod:(916) 348-4278:250:100:175 Chet Main:(510) 548-5258:50:95:135 Tom Savage:(408) 926-3456:250:168:200 Elizabeth Stachelin:(916) 440-1763:175:75:300 output should contain the lines ...
1
vote
3answers
396 views

grep equivalent of the kwrite regex [A-Z][A-Z]+

So, it took me ages, but I finally learned to think in terms of regular expressions, thanks to using them in kwrite. But I still don't know how to translate that knowledge to grep. I love my grep, ...
1
vote
1answer
1k views

Difficulty making a regular expression to find at least 2 occurrences of a character in a file

I have a file containing random codes. Each code has ten characters in it, and I am trying to grep codes in the file that have at least 2 occurrences of a character. I am doing this: grep DD* ...
1
vote
2answers
5k views

Using grep to match only a match group in a regular expression?

I need to set my keyboard layout with setxkbmap before launching Wine games, as I use Dvorak for typing and this breaks every game's controls. What I'd like to do is simply write a script that grabs ...
1
vote
4answers
3k views

Match multiple regular expressions from a single file using awk

I'm trying to parse a HTML file using shell scripting. There are 4 different regular expressions that i need to catch: name= , age= , classs= , marks=. Using grep "name=\|age=\|class=\|marks=" ...
1
vote
3answers
571 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
3answers
764 views

Trying to remove all ids from an HTML file with grep

I'm trying to remove all id=" "s from an .html file but I'm not sure where I am going wrong. I tried using regular expressions but all I am getting is the .html file rendering in my Ubuntu terminal. ...