Hot answers tagged

6

--color adds escape sequences for the color. You can see this if you redirect the output (of ls --color) to a file. This is what it looks like: drwxr-xr-x 6 root root 4.0K Jan 9 08:23 ^[[01;34m.cabal^[[0m/ To account for this, try this instead: ls -lhAF1 --color | grep -E '^d.*[0-9]{2}:[0-9]{2} .*\.'


6

Parsing ls is often a bad idea. Often, but not always. Here's another suggestion for you, which collects the required directories together before passing the set to ls. find .* -maxdepth 0 -type d \( -name '.[^.]' -o -name '.??*' \) -exec ls -ld --color=always {} + It's been pointed out that the original code actually limits the list of directories to ...


5

Collation elements are usually referenced in the context of sorting. In many languages, collation (sorting like in a dictionary) is not only done per-character. For instance, in Czech, ch doesn't sort between cg and ci like it would in English, but is considered as a whole for sorting. It is a collating element (we can't refer to a character here, character ...


4

:%s:.*:<a href="&">&</a>: Same as in ed/sed/perl... Another less ex and more vim-like way would be: if you know how to do it once for a line, record it as a macro and then run :%normal @m where m is that macro. Like (in normal mode): qmS<a href="<Ctrl-R>""><Ctrl-R>"</a><Esc>q to record the macro.


3

If you have the rename implementation with Perl regexes (as on Debian/Ubuntu/…, or prename on Arch Linux), you need $1 instead of \1. Also, no backslashes on capturing parentheses: rename 's/(.*)_(.*)/$2_$1/' *_* If not, you have to implement it yourself. #! /bin/bash for file in *_* ; do left=${file%_*} right=${file##*_} mv "$file" ...


3

Check your single quotes. Single quotes don't magically nest. alias sll 'ls -l \!* | grep -oE '\''[^ ]+$'\'' | xargs ls -ld --' That's still flawed for several reasons: Because of [^ ], that won't work for file or link target names that contain spaces. as you're treating that list as a list of lines, that won't work with file/link target names that ...


3

You could use grep with -A. Something like: $ grep -A 13 '^\[2\]' inputfile.txt The -A specifies the number of lines you want to include after the match. But I think it would be better to use sed in this case: $ sed -n '/^\[2\]/,/^$/p' inputfile.txt This will print everything between [2] and an empty line. The same using awk: $ awk -v RS='' -v ...


2

Regarding to above input examples the script can be: sed s/[^\"\']*[^0-9]\]{\(.*\)}/\1/ <<\END "[]{foo bar 1}" "[abc]{foo bar 2}" "[]{foo[3]{xyz} bar 3}" "[]{foo $sq[3]{xyz}$ bar 4}" "[goo{w}]{foo $sq[3]{xyz}$ bar 5}" "[goo[3]{w}]{foo $sq[3]{xyz}$ bar 6}" "[goo[3]{w} hoo[3]{5}]{foo $sq[3]{xyz}$ bar 7}" END produces "foo bar 1" "foo bar 2" ...


2

The reason is that ls always colorizes its output even if it is connected to a terminal. From man ls: --color[=WHEN] colorize the output. WHEN defaults to 'always' or can be 'never' or 'auto'. More info below Many other tools such as grep do not retain colors when standard output is terminal but for some reasons ls was ...


2

POSIXly: $ sed -e '/<!--/{ $!N s/.*on // }' <in >out


2

The following sed command should do what you want: sed '/^<!--/{N; s/.*on *//}' inputfile First we search for the regex <!-- at the beginning of the line, than we use the N command to append the next line to it and delete (substitute with nothing, actually) everything till and with "on". There are people claiming that whenever you use a capital ...


2

You can use sed: sed -ne '/^[0-9][0-9]*\.[0-6]/ { N; s/\n/ /; s/^\([^,]*,[^,]*\),.*$/\1/; p; }' < data This processes a file called data, suppressing printing unless asked for (-n) and executing the sed program in quotes. That program selects lines starting with one or more digits, a ., and a digit 0-6, and then runs the part in {} for those lines. ...


2

Here is an example -- .* means 0 or more of any character. In the 2nd case it matches 0 of any character followed by one of the non excluded characters. ls 1 a =a ++a a.0 a_1 B b0 find . . ./B ./=a ./b0 ./a_1 ./a ./1 ./a.0 ./++a find . -regex '.*[^-_./0-9a-zA-Z].*' ./=a ./++a


2

.* is followed by [^-_./0-9a-zA-Z] - and it is not optional. So something other than one of those characters (the alphabets, digits, -, _, . and /) should appear once in the filename. Any path which consists solely of these characters will not be printed. Therefore these commands need not output the same results.


1

why do you use the Pipe? :%s/.*/\<a href=\"&\"\>&\<\/a\>/g (mark all command strings with \ )


1

Run scp once, then copy it locally on the remote server. $ scp file.txt my-remote-vm-1:/tmp $ ssh my-remote-vm-1 'for i in /tmp/conf-[0-9]-ver-[0-9]; do cp /tmp/file.txt "$i"; done' $ ssh my-remote-vm-1 rm /tmp/file.txt


1

Postfix provides a way to do this without resolving to manual filtering: sudo postconf mail_name=SomeRandomMTA From the postfix docs: mail_name (default: Postfix) The mail system name that is displayed in Received: headers, in the SMTP greeting banner, and in bounced mail.


1

Perl can read the whole file with -0777, the /s modifier makes . match newlines, too: perl -0777 -pe 's/<!--\\.*?on //gs' *? is a "frugal asterisk", which means "repeat zero or more times, but match the shortest string possible".


1

I am not fully aware of LibreOffice's internal syntax, but if you are talking about regex, as in regular expressions, you will have to use the digit symbol \d.


1

I'm assuming your string variable is one long line without newlines. I get a sed error complaining about an unknown option to the s command. That's because your string contains slashes, which is the delimiter for the s command. Using bash parameter substitution to esacape the slashes in the string works. $ cat file this is a _PLACEHOLDER_ here $ ...


1

Pass the variable doublequoted as an argument to Perl, it can handle special characters in variables in the replacement: perl -i~ -pe 'BEGIN { $replace = shift } s/_PLACEHOLDER_/$replace/g ' "$text" "$file"



Only top voted, non community-wiki answers of a minimum length are eligible