0
votes
1answer
32 views

is there a way i can either insert a character into a line or substitute and arbitrary character with itself plus some other carachter(s) in sed?

like say i have a string of numbers that constitute a phone number and are like so ########## and i want to format them like : ###-###-#### insert only puts in new lines, and i dont know how to ...
0
votes
1answer
29 views

Linux find files in subdirectories by extension (.txz) then move them to specified directory using regular expressions

I have mirrored a directory from a server with a large number of sub directories, each of which contain a .txz package and the usual .txt and descriptor files. What I would like to do is the ...
0
votes
1answer
116 views

Bash: exact match of a string with regex

I have to do an exact match on a string with a regex. i have to realize this pattern: toCheck must start with 2 occurrence of $str1, with max 1 occurrence of $str2. If toCheck match the pattern, i ...
0
votes
3answers
24 views

text file — search via regex, bold the results in order to physically print out

i can't think off the top of my head an app which will allow me to do this. i have a document with hundreds of lines, i want to search via a regular expression and either bold or italicise the hits. ...
-4
votes
1answer
62 views

Remove two dots back from end of line

I need to use regex to remove all text starting at the end of line and going back two dots. gtk2-2.24.22-2.fc20.x86_64 becomes gtk2-2.24.22-2 This is the output from rpm -qa to a text file, and ...
4
votes
1answer
150 views

Bash regex to rename set of files

I have to rename a set of files, using the rename command (with a regular expression).  After some tries, I'm not able to find an expression that gets the expected result. I've got a file pattern ...
4
votes
2answers
37 views

Rename ':2f' to '-' on folder names in Linux

I've got a hard drive taken from a NAS drive where files had been put on from a Mac - However, some of the filenames had been, for example, 'backup 16/07/14' which has then been changed to 'backup ...
0
votes
2answers
55 views

How to download all file with name emp* using curl from a FTP site

How can I get all files downloaded from a FTP site directory with file name like emp*. Please suggest.
3
votes
2answers
2k views

Grep: count number of matches per line

I'm trying to get the number of matches (in this case occurrences of { or }) in each line of a .tex file. I know that the -o flag returns only the match, but it returns each match on a new line, even ...
0
votes
1answer
116 views

using sed to replace 1 line with a multi-line variable in ksh

I have the following text in a file: XXXX NNNN YYYY NNNN ZZZZ NNNN I want to replace the NNNN to make it look like this: XXXX NNNN DUTY FORECASTER: YYYY NNNN DUTY FORECASTER: ZZZZ NNNN ...
3
votes
2answers
2k views

How to search a text file for strings between two tokens in Ubuntu terminal and save the output?

How can I search a text file for this pattern in Ubuntu terminal and save the output as a text file? I'm looking for everything between the string "abc" and the string "cde" in a long list of data. ...
2
votes
1answer
61 views

find -regex not recognizing \d digit

I have a directory structure that looks like the following: processor0/10 processor0/10.1 processor0/10.2 processor1/10 processor1/10.1 processor1/10.2 ...etc... processor7/10 processor7/10.1 ...
2
votes
1answer
42 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 ...
1
vote
3answers
103 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
51 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
198 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
445 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> ...
2
votes
2answers
265 views

How to grep a line with a backslash at the end of the line?

I'm trying to grep a line with a backslash at the end of the line like: abc\ def ghij ... I hope it can grep the line "abc\". I tried the command below but they didn't work. grep -EHn "\\$" ...
0
votes
2answers
149 views

Find and replace with sed, keep original line too

I have param1='123' I would like param1='123' param2=123 where 123 will change between the files I'd like to run this on. I can get param2 using sed -i "s/param1=\([0-9]\+\)/param2='\1'/g" ...
0
votes
3answers
34 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
163 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 ...
0
votes
1answer
66 views

linux find regex - can I use 'search', instead of match?

the find utility is powerful, but I'd need some additional features. its -regex search treats each filename (or dirname) as a string and applys given regex only at the beginning of name. like ...
1
vote
2answers
75 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
268 views

How can I find all files on a folder tree that have a none alpha numeric characters in it

I have taken over from someone else a lot of historic data. However the file names are totaly random and badly formatted IMHO. To start with I want to get a list of all files that contain spaces, or ...
2
votes
3answers
146 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
157 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 ...
2
votes
3answers
169 views

sed regexp address case-insensitive matching

How to specify a sed regexp address which is case-insensitive? E.g., sed '/my-kw/d' But I want sed to remove lines with my-kw in any cases. Thanks
1
vote
1answer
75 views

Matching html paragraphs with at least one word in all caps

Using regex or anything, I need to match any paragraph which contains at least one all caps word. Then transform it into a header and capitalise all the content of the title. In the example below, ...
0
votes
2answers
50 views

How to grep a number following a keyword from a textfile?

How to grep the member id X01930 from the following file? Blah Blah ... Blah Blah Blah Blah ... Member ID: X01930 Blah Blah ... Blah ... Blah Blah ... Blah The string Member ID: is usually there, ...
3
votes
2answers
152 views

Prefix all lines with the first word in a file

I want to prefix all the lines of a file (except first line) using the first word in a file. Input: x.o: x.cpp /u/a.h /b.h \ /c.h \ output: x.o: x.cpp /u/a.h \ x.o: /b.h \ x.o: /c.h \ Can ...
0
votes
1answer
910 views

How can I use lookahead and lookbehind regular expressions on Linux using find?

I generally use the following command to match patterns find . -maxdepth 1 -regextype posix-egrep -regex '.*/{pattern}' However when I attempt to use a lookahead for example, no results are ...
2
votes
3answers
443 views

Linux GUI Regular Expression File Renamer (with substitution)

I have folder with several hundred files named like this: 010203.txt I want to rearrange the file names so that last two digits are moved to the front like this: 030102.txt I want to avoid writing ...
0
votes
1answer
55 views

Search files for regex and return which files contain matches

I searched everywhere but didn't find out how to return a file content that matches given words or a regex. cat /tmp/*.txt | grep "strings"
0
votes
4answers
328 views

Regular expression to find senders IP using grep or other languages

I have input file that contains: 19:04:01.631948 IP (tos 0xc0, ttl 1, id 0, offset 0, flags [none], proto UDP (17), length 48) 181.173.82.61.1985 > 250.66.33.195.1985: HSRPv0-hello 20: ...
1
vote
2answers
3k views

Match regex pattern only in filename.extension

I need to use find to locate a file matching a regex pattern in filename.extension instead of the default, which matches /path/to/filename.extension. For instance: /folder |--a-love-song.ogg ...
-1
votes
2answers
135 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
1answer
355 views

zsh fail to expand apt-get regex?

zsh seems to fail expand apt-get regular expression. For instance I would like to install all packages that has the prefix llvm-3.1, and I use: sudo apt-get install llvm-3.1* But zsh tells me that: ...
1
vote
2answers
163 views

How do I list every other file extension using regex on Linux?

I have the following command which lists all files that have the extension .swf however I would like to return a list of every file that does not have the extension .swf find . -maxdepth 1 -regextype ...
0
votes
1answer
311 views

Nano syntax highlighting malformed regex?

I found this javascript syntax highlighting file for nano on google code, downloaded it and included it in my /etc/nanorc file: File: /usr/share/nano/js.nanorc ## all *js files ( e.g. Firefox ...
0
votes
0answers
64 views

How to replace file strings with regexp in Linux

I'm trying to replace the specific numbers and use this command: sed -e 's/[0-9]\{12\}/ /g' file.log but nothing happens. As U can see this expression should replace all numeric occurrences with ...
4
votes
4answers
78 views

Apply regex to certain occurrences

I have a large file with plain text (no html tags, etc.). What I want to do is to apply regex to whole file on the one hand but on the other I want to choose which changes will be applied. For ...
0
votes
6answers
752 views

grep *.c not working

I have a list of ".c" (c files) in the current directory. I have to find all the .c files in the current directory. The command that can be used id ls *.c But, another way is to use grep. so if i ...
5
votes
4answers
7k views

rsync using regex to include only some files

I am trying to run rsync to copy some files recursively down a path based on their file name pattern, case insensitive. This is what I have done to run rsync: $ rsync -avvz --include ='*/' ...
0
votes
1answer
980 views

Why does the following find regular expression not work on Linux?

I am attempting to locate files that match a particular pattern however attempting to run the command below returns no results even though there are files that should match the pattern. find . ...
1
vote
1answer
587 views

Add, replace or delete something/everything between two strings with regexxer

I'm using regexxer to translate an application that use .php files. In accordance to the webpage it's based on usage and syntax of Perl regular expressions. It looks more to be applied to Perl code. ...
1
vote
1answer
51 views

Automatic replacement of expressions

Maybe this can be achieved through (extended) regular expressions, but I really don't know if or how. There seems to be a way to access "things that are found" by using $1, $2, … but I have no idea ...
1
vote
3answers
145 views

How to remove text from vim

I want to remove all the words that ending with abc Example: 111abc 222def 333abc 444def 555abc 666def From here I want to delete all the words that ending with abc. so I tried this ...
0
votes
2answers
380 views

GUI search tool in linux

Coming from windows, there is a fantastic search tool, called find everything, found here: http://www.voidtools.com/ Which can instantly search all files on your hard drives via name. It does not ...
0
votes
2answers
2k views

rm command and regular expressions via Linux BASH shell

I am attempting to use regular expressions to remove set of files however the bash shell returns the message rm: cannot remove `[0-99]+ -': No such file or directory rm: cannot remove `[a-zA-Z': No ...
2
votes
3answers
103 views

using vims pattern-multi-items {n} to match the 5th space in a line

With this entry from our crontab 1 3 1 * * find /var/log/tomcat/* -mtime +61 -type f -delete I want to match the 5th space char so I can separate the command part from the time field part. Cron ...