Tag Info

New answers tagged

0

Definitely different yum version, using RHEL 6.5 here with yum 3.2.29 Beware: You should escape the * to not match anything in the current directory via shell globbing ... Anyways, just checked again, the only way to actually search effectively with yum search is by yum search all | grep foo as yum search foo gives pretty fuzzy results. But yum list foo-* ...


3

searching with YUM You generally don't use any regular expressions when searching withyum search since the command search is already looking for sub-strings within the package names and their summaries. How do I know this? There's a message that tells you this when you use yum search. Name and summary matches only, use "search all" for everything. So ...


0

Sorry cannot comment yet so have to use an answer. Did you try yum search cl-* or yum list 'cl-*' ? At least for yum whatprovides */foo it works for searching filenames, although that's a bit of a special case. Otherwise I also often use yum list all | grep -i foo but beware of the multiline output of yum, grep might only show the first line, so maybe use ...


9

* in shell patterns matches 0 or more characters. It's not to be confused with the * regular expression operator that means 0 or more of the preceding atom. There is no equivalent of regexp * in basic shell patterns. However, various shells have extensions for that. ksh has *(something): ls a_*([a-z])_data you can have the same in bash with shopt -s ...


18

So the problem is: why does a_[a-z]*_data match a_clean_0db_data? This can be broken down into four parts: a_ matches the beginning of a_clean_0db_data, leaving clean_0db_data to be matched [a-z] matches any character in the range a-z (e.g. c), leaving lean_0db_data to be matched * matches any number of characters, e.g. lean_0db _data matches the trailing ...


26

The [a-z] part isn't what matches the number; it's the *. You may be confusing shell globbing and regular expressions. Tools like grep accept various flavours of regexes (basic by default, -E for extended, -P for Perl regex) E.g. (-v inverts the match) $ ls a_[a-z]*_data | grep -v "[0-9]" a_clean_data If you want to use a bash regex, here is an example ...


1

sed '$!N;/###$/s/IDLE/END/;P;D ' <<\DATA 22 Aug 19 16:47:33.159: <DATA> |POS|RINGING|1|1126710938|5950|$hostIp|$size |$data 23 Aug 19 16:47:33.453: <DATA> |POS|INIT|1|1126710938|5950|$hostIp|$size |$data 24 Aug 19 16:47:33.484: <DATA> |POS|TRAINING|1|1126710938|5950|$hostIp|$size |$data 25 Aug 19 16:48:05.824: <DATA> ...


2

Try: $ awk '!/^#+$/ {print l; l=$0; next} {gsub("IDLE","END",l); print l; l=$0} END {print $0}' < log.txt which gives: Aug 19 16:30:11.506: <DATA> |POS|IDLE|1|01131844090|5950|$hostIp|$size |$data Aug 19 16:30:12.439: <DATA> |POS|END|1|01131844090|5950|$hostIp|$size |$data ...


2

Update: The ex command way will work only on the first matching line. The perl example will replace for all lines with the pattern, but will only give the output and not edit the origitnal file, so you will have to redirect the output to a new file. YOUR-LOGFILE should be replaced by the location of the file you are trying to modify. perl -0pe ...


1

Most Linux: sed -i 's#FIND#REPLACE#g' *.{php,ini,conf,sh} On MacOS: sed -i '' 's#FIND#REPLACE#g' *.{php,ini,conf,sh} The sed in MacOS is expecting a backup parameter after -i, use empty string if you don't need backup files. The "g" is for global replace, otherwise it's only the first per row.


2

With GNU sed you can use sed -i. sed -i 'script' *.{php,ini,conf,sh}


2

Typically, when you get a > in the next line after hitting, it means that one of your quotes isn't closed yet. I couldn't find that mistake in your regex. But you do not need to surround the path /var/www_data/somepath/ with single quotes. I assume there are no unusual characters in somepath? Anyways, I tested your regex with sed. \d\w look like vim ...


4

Assuming that your logfile is called logfile, here is an awk solution with the sample output: $ awk '/RINGING/,/CLOSE/ {if (/30 30/){f=1}; a=a"\n"$0} f==0 && /CLOSE/ {print a} /CLOSE/{a="";f=0}' logfile 313782 Aug 19 18:37:04.925: <DATA> RINGING|254|01136097645|5950|$hostIp|$size |$data 313783 Aug 19 18:37:05.262: <DATA> ...


2

It may be possible using a perl compatible regex (PCRE) for example pcregrep -M '^.*?RINGING(?(?!30 30)(?s).)+?CLOSE.*?$' file or grep -zPo '^.*?RINGING(?(?!30 30)(?s).)+?CLOSE.*?$' file Alternatively, using GNU awk's more expressive record separator gawk -vRS="CLOSE[^\n]*\n" -vORS= '!/30 30/ {print; print RT}' file


0

Well one option is sed although this may be substantially slower than the grep alternative cut -d: -f2 states.txt | tail -n +2 | sed -n -e '/a/I{/r/I{/n/Ip}}' Arizona Arkansas California Maryland Nebraska New Hampshire North Carolina North Dakota Rhode Island South Carolina Virginia West Virginia


2

The grep command does not have a proper AND operator so you have to get creative when trying to solve problems such as this one. You can do, as you've elected to do and chain multiple grep's together. But you can also do something like this: $ echo -e "arie\narin" | grep -i '[arn].*[arn].*[arn]' arin This will match any strings that contains a combination ...


0

cut -d: -f2 states.txt | tail -n +2 | egrep -i '[arn].*[arn].*[arn]'


2

You should use awk: $ awk '/a|A/ && /R|r/ && /N|n/' file Arizona Arkansas California Maryland Nebraska New Hampshire North Carolina North Dakota Rhode Island South Carolina Virginia West Virginia With gawk, you can use IGNORECASE: gawk '/a/ && /r/ && /n/' IGNORECASE=1 file


2

perl -pe 'print "\n" if $c and !/^(?!\d+,\d+)/; $c=chomp; END{print "\n" if $c}' file_name


3

Try: $ perl -00pe 's/\n(?!\d+,\d+)//g' file 1407233497,1407233514,bar 1407233498,1407233515,foomingstats&fmt=n 1407233499,1407233516,foobar perl read file line by line by default with -p option, so your regex can not work. -00 option turns paragraph slurp mode on, your regex now can work on multiline. From perldoc perlrun: -0[octal/hexadecimal] ...


1

You don't specify any tools, so I use perl as example: $ echo Pty[R=4]@ID | perl -nle ' print "$1\n$2\n$3\n$4" if /^([a-zA-Z0-9]*)(\[([a-zA-Z0-9=]*)\]){0,1}@([a-zA-Z0-9]*)$/ ' Pty [R=4] R=4 ID $ echo Pty@ID | perl -nle ' print "$1\n$2\n$3\n$4" if /^([a-zA-Z0-9]*)(\[([a-zA-Z0-9=]*)\]){0,1}@([a-zA-Z0-9]*)$/ ' Pty ID With regular ...


1

I think, it's better to replace \n symbol to some other, and then work as usual: e.g. not-worked source code: cat alpha.txt | sed -e 's/a test\nPlease do not/not a test\nBe/' can be changed to: cat alpha.txt | tr '\n' '\r' | sed -e 's/a test\rPlease do not/not a test\rBe/' | tr '\r' '\n' If somebody don't know, \n is unix line ending, \r\n - windows, ...


1

With my PatternsOnText plugin, you can restrict :substitute commands to pattern matches (\cite{...} in your case): :%SubstituteInSearch/\\cite{[^}]\+}/\(\d\+\)-\(\d\+\)/\=join(range(submatch(1),submatch(2)), ',')/g The regular expression parses the start and end numbers, and transforms them into the number range via join() and range(), using :help ...


2

To expand any single instance of a range of the form m-n within a \cite{...} expression, you could perhaps do something like perl -pe 's/\\cite{(?:\d+,)*\K(\d+)-(\d+)(?=(?:,\d+)*})/sprintf "%s", join(",", ($1..$2))/e' file.tex


3

You can use vim's substitute command to accomplish this: :%s/\\cite{1,3-7,9}/\\cite{1,3,4,5,6,7,9}/g This will replace all occurrences of \cite{1,3-7,9} with \cite{1,3,4,5,6,7,9}. To replace only occurrences that exist on the current line you can use: :s/\\cite{1,3-7,9}/\\cite{1,3,4,5,6,7,9}/g Append c if you want vim to ask for confirmation ...


3

At least in GNU sed, I think you can do something like sed -e '0,/pattern/ s//replacement1/' -e '0,/pattern/ s//replacement2/' file e.g. given a file abc def abc ghi abc jkl then $ sed -e '0,/abc/ s//XYZ/' -e '0,/abc/ s//UVW/' file XYZ def UVW ghi abc jkl


1

( set -f; IFS=' '; printf '%s %s\n' $(grepcmd <input) ) >output IFS will be happy to eat it if you want.


0

After search around the web, alternative way of Lekensteyn is the better one I found. But I want use dif output as patch... and there is a problem because line number are note keeped because of "grep -v". So I purpose to improve this command line : diff -u -B <(sed 's/^[[:blank:]]*#.*$/ /' file1) <(sed 's/^[[:blank:]]*#.*$/ /' file2) It's not ...


0

( scale=${scale##*[!0-9]*} : ${scale:?input must be an integer} ) || exit That does the check and outputs your error.


-1

wrap your sed/grep in backticks when your original command was: grep -i 'foo' mylog.log | sed 's/bar/baz/gi' your new command would be: `grep -i 'foo' mylog.log | sed 's/bar/baz/gi'` Doesn't get the spaces in between lines, but you can always tack on another sed pipe: | sed 's/$/ /'


2

Remove quotes if ! [[ "$scale" =~ ^[0-9]+$ ]]


2

Use -eq operator of test command: read scale if ! [ "$scale" -eq "$scale" ] 2> /dev/null then echo "Sorry integers only" fi It not only works in bash but also any POSIX shell. From POSIX test documentation: n1 -eq n2 True if the integers n1 and n2 are algebraically equal; otherwise, false.


2

A simple way, pipe output to xargs: $ echo -e 'a\nb' | xargs a b This only works with small ouput, because it's limited by maximum characters per command line. The largest value depends on system, you can get this value using getconf ARG_MAX.


2

With sed, you can do this: <your previous commands> | sed '{N; s/\n/ /}' N; tells sed to add the next line into the pattern space, so now sed is working with both lines. s/\n/ / replaces the newline character with a space, "merging" the two lines together.


6

I'll put three versions different methods in a row AWK printf %s\\n pattern1 pattern2 | awk -vRS="\n" -vORS=" " '1; END {print RS}' SED printf %s\\n pattern1 pattern2 | sed '$!N;s/\n/ /' TR printf %s\\n pattern1 pattern2 | tr '\n' ' '; echo And there are many more.


2

you can do it using shell script or in command-line, just put the output of the command in a variable then echo it: # x=$(grep -e "pattern1\|pattern2" test) # printf '%s\n' "$x" pattern1 pattern2


7

paste: {...pipeline...} | paste -d " " - - That says: "read a line from stdin (the first -), read another line from stdin (the second -), then join them with a space" a bash-specific technique: $ x=$(grep -o pattern. test.txt) $ echo "$x" pattern1 pattern2 $ mapfile -t <<< "$x" $ echo "${MAPFILE[*]}" pattern1 pattern2 ref: ...



Top 50 recent answers are included