Reputation
12,965
Top tag
Next privilege 15,000 Rep.
Protect questions
Badges
1 26 52
Impact
~543k people reached

11h
comment Extracting with grep/sed a first pattern and then a second pattern that occured some lines before and related to the first
Indeed, the code works fine with the given input sample.
18h
answered How to read first and last line from cat output?
20h
revised finding lines in a file matching patterns defined in another file
match using fixed strings, it's faster
20h
revised finding lines in a file matching patterns defined in another file
retag, edit code to match output
21h
comment what is difference between /usr/lib and /etc/systemd?
man systemd.unit
21h
comment Odd output from fdisk -l: overlapping and missing partitions?
1) sda2 is a "container" of other partitions (sda5 in your case). 2) There are no sda3 and sda4 on your system, you only have one primary partition (sda1) and one extended partition (sda2). Read on partitions here
1d
comment awk search for string containing forward slash in variable
@Koveras - ah, my bad - I used your sample as test file. This should work (unless I'm missing something again) : grep -n . infile | sed -n '/^[0-9]*: </{x;/errorpages\//{p;d}};/errorpages\//H' (always four spaces between : and <)
1d
comment How can I quickly sum all numbers in a file?
Yep, that's the calculator. printf %s\ 0 $(tr times=c'\n' ' +' <infile) p | dc for the picky ones who want to get just the final result (there are two spaces after the backslash and seven spaces between ' and +)
1d
comment awk search for string containing forward slash in variable
@Koveras - Pass shell variable as a /pattern/ to awk... but unless I'm missing something this could be easily done with grep/sed. Give it a try : grep -n . infile | sed -n '/^[0-9]*: </h;/errorpages\//{H;x;p}' (there are four spaces between : and <)
1d
revised source multiple files and output one file
deleted 37 characters in body
1d
answered source multiple files and output one file
2d
comment Find the complement set of an array?
Interesting approaches... I would have used printf '%s{w random10\nd}\n' $(shuf -i 1-100 -n 10) | sed -f - infile > remaining90
2d
answered How can I count the number of times a phrase appears in a file, and format it neatly?
2d
revised Use different filtering criteria with tcpdump packet size
format
2d
revised How can I quickly sum all numbers in a file?
added 4 characters in body
2d
comment Is it possible to pass arguments to a sed script?
If foo occurs 10.000 times in some-file.txt this will run 10.000 additional substitutions. You're better off altering the script: sed 's/#ARG1#/bar/' foo-to-bar.sed | sed -f - some-file.txt
2d
comment Append something to each list in a file
@Koveras - no problem. The difference is minimal, it just saves you some typing/escaping and as a result it is (IMO) easier to understand. The -E switch enables sed extended regex so you no longer have to escape parentheses when grouping, e.g. ([^[]*) instead of \([^[]*\). Also, you can use \n instead of a (escaped) literal newline. Other than that it's the same sed command, it does the same thing. The other difference: <(command) is called process substitution. So command2 <(command1) is just another way of writing command1 | command2
May
26
comment Combining large amount of files
Couple of things here... -1 isn't needed with ls when piping the output. If the order of pasting matters you might want to do some additional sorting (e.g. ls res.* | sort -t\. -k2n | split ...) otherwise ls will list e.g. res.1, res.10, res.100, res.2, res.3 etc. find results will be completely mixed up so that would also need sorting (if needed). Also, it's find . -maxdepth 1 -type f not find . -type f -maxdepth 1. Other than that, +1.
May
26
comment Append something to each list in a file
@Koveras - :) I'll take that as a compliment... I've added a gnu sed alternative that does the same thing (other seds might work too if they support ERE and i\\\n)...
May
26
revised Append something to each list in a file
added 444 characters in body