New answers tagged

1

If your paths don't contain spaces or semicolons, just turn the semicolons into spaces. tr ';' ' ' | uniq -f 1 -d | tr ' ' ';' If your paths contain spaces but no tabs or semicolons, you can do basically the same thing — but temporarily turn spaces into semicolons, and use a tab as the field separator. tr '; ' '\t;' | uniq -f 1 -d | tr '\t;' '; ' If ...


1

Possible solution could be using following awk: awk -F";" 'FNR == NR { x[$2]++; next; } { if ($2 in x && x[$2] > 1) print; }' file file Caveat with this is that file is read twice. In the first pass we count and store repetitions in array and in the second pass we print row if counter is greater then 1.


0

perl 1-liner: perl -lne '$u=$1 if(/^DATA display (\S+)/);print "$u,$1" if(/^DATA pass (\S+)/)' filename


2

With GNU sed: sed -n '/^OBJECT NickCore/,/^END/{s/^DATA display //;Ta;h;:a;s/DATA pass //;Tb;H;g;s/\n/,/p;:b}' file See: man sed


0

So if you wanted to get just the time value without the ms label: HOST="127.0.0.1" PING_MS=`ping -c1 "$HOST" | /usr/bin/awk 'BEGIN { FS="=" } /time=/{gsub(/ ms/, ""); print $NF; exit}'` This gives me: 0.058 Now, if we wanted to test if time>=50.0, we could use awk for this, too, since POSIX sh itself can't compare decimal numbers: if echo ...


0

simply cat $YOUR_FILE | sed 's/ /\t/' > $NEW_FILE


4

<"$YOUR_FILE" sed 's/ a$//' > $NEW_FILE will do the trick i think.


1

Using sed: sed -e "s/ /$(printf '\t')/" <file


1

Using awk is probably the best here since it lets you express your thought clearly (strip the tags, there must be at most 4 words left, not including the first column). But you can also do this with grep, since it's just a matter of filtering lines and the filter can be described by a regular expression. grep -vE '^ *[^ ]+((<[^>]*>| )+[^<> ...


1

POSIX-compliant sed solution which produces 0019093203 from the sample data (assumes Invoice information follows "ODSTATION BUSY"): sed '/.*ODSTATION BUSY.*Invoice #: */!d; s///; s/\\n.*//' file A tweaked version of don_crissti's approach to handle either case: sed -n '/ODSTATION BUSY/s/.*Invoice #: \([0-9]\{1,\}\)\\n.*/\1/p' file


1

perl -e 'while(<>) {if ($_ =~ qr/ODSTATION BUSY/) { print "$1\n" if $_ =~ /Invoice #:\s+(\d+)/ } }' <yourfile_goes_here> Oh, Bash? grep 'ODSTATION BUSY' filename |egrep -o 'Invoice[^0-9]+[0-9]+'|egrep -o '[[:digit:]]+' Or: awk 'BEGIN{$0 ~ /ODSTATION BUSY/}; gsub(/^.*Invoice #: /,""){print $1}' filename |sed 's/\\n.*$//g'


0

if there are too many lines, like in the order of thousands, I prefer to use a temporary file rather than extracting them in the memory and causing system load, but this is a preference of mine. grep "ODSTATION BUSY" logfile > workfile cat workfile | while read line do invoffset=$(echo ${line} | grep -b -o "Invoice #:"|cut -d: -f1) #locates string ...


0

One way of doing this would be: $ grep "ODSTATION BUSY" <filename> | sed 's/^.*Invoice #://;s/\n.*$/' That's pretty ugly, I'm sure there are other, possibly better, ways of pulling this information out using something like awk.


1

for i in $(cat myfile.txt|cut -d"_" -f 1 | sort | uniq) do grep ${i} myfile.txt > ${i}.txt done This should work


1

Your Åström has decomposed unicode characters, not precomposed ones: (I'm assuming the current locale uses UTF-8 and those characters entered on the command line use UTF-8 encoding here (I've copy-pasted them from a browser using UTF-8)). $ printf %s Åström | uconv -x any-name \N{LATIN CAPITAL LETTER A}\N{COMBINING RING ABOVE}\N{LATIN SMALL LETTER ...


0

The solution I used is to use Emacs. I open the file, find the part with accents, copy a character with accent and one character before the accent. I go to the beginning of file, run M-x replace-string, paste what I copied, go to the beginning of the minibuffer, delete the character that was before, and run the command. I figured that the accent was more ...


2

The following AWK script saves the original line in x, deletes all the tags, and then counts the number of words (minus 1 to discount the filename in the first field). If the word count is less than 5, it prints the original line: awk '{x=$0; gsub(/<[^>]*>/, "")} NF-1<5 {print x}' filename


1

There is a perl module Text::Unaccent available from CPAN for your purpose: http://search.cpan.org/~ldachary/Text-Unaccent-1.08/Unaccent.pm A sample perl script (working from STDIN to STDOUT) may look like: #!/usr/bin/perl use Text::Unaccent; while ($zeile = <STDIN>) { print STDOUT unac_string("UTF-8", $zeile); }


2

Could be done with a small python script: #!/usr/bin/env python3 import sys for l in open(sys.argv[1]).readlines(): l = l.strip() print(l) if len([s for s in l.split("<s>")[-1].split() if not all([s.startswith("<"), s.endswith(">")])]) <= 4 else ("") Assuming you have python3 installed: Copy it into an empty file, ...


0

This command should work: awk -F "wav" '{print $2}' file | awk '{gsub("<[^>]*>", "")}1' | awk 'NF<4'


0

please try this i hope this is helpful for you grep -Pv '\t' "test.txt" "v" option is use to invert matching and "P" for pattern in below image last two line not contain tab


1

Enumerating the files Parsing the output of find is fragile. Better make find invoke the transformation program. To generate the output file name, a simple parameter expansion is enough to change the suffix _times.csv into _subtracted.csv (for example). find logs_swapoff -name '*_times.csv' -exec sh -c ' <"$1" awk "$0" ...


2

It is certainly possible to use the file list generated during a dry run as an include file. Ideally, however, the extra lines at the top and bottom of the dry-run output should be deleted. Example output: sending incremental file list [LIST OF FILES] sent 226 bytes received 34 bytes 520.00 bytes/sec total size is 648,373,274 speedup is 2,493,743.36 ...


3

To sort from highest to lowest: grep -rc 'Author' $1 | sort -r -t ':' -k2,2n -r sorts in reverse order, that is, from highest to lowest. -t introduces the separator. -k introduces which fields to sort by. The fields are separated by the separator defined by -t. This syntax means to sort by all of the fields between 2 and 2 (so just the second field). The ...


3

grep -rc 'Author' $1 | sort -t : -k 2,2n is good if you want the number of lines containing the keyword, regardless how many times it repeats on any given line. If you want the actual word count, you should use this echo $1:$(grep -o 'Author' $1|wc -l) | sort -t : -k 2,2n -o option for grep is most probably available on the gnu version of grep. If you ...


3

The -n flag of sed means quiet. The automatic printing of lines is diabled then, and you have to explicitly print a line with the p command. Just use your command without -n or with p at the end: sed 's/},{"Foo"/}\n{"Foo"/g' file >output Or: sed -n 's/},{"Foo"/}\n{"Foo"/gp' file >output


0

This perl code produces almost exactly the expected output: use Text::CSV; my $csv = Text::CSV->new({ binary => 1, eol => $/, allow_loose_quotes => 1, escape_char => undef }); open my $io, "<", $ARGV[0] or die; while (my $row = $csv->getline ($io)) { my @o = map { $_ =~ s,^\s*,,; $_ =~ s,\s*$,,; $_; } @{$row}; ...


0

Here's a quick and dirty solution: sed -n 's/^.*href="\([^"]*\)".*$/\1/p; s/^.*\(£[0-9.]*\).*$/\1/p' | awk 'NR % 2{ printf "%s, ", $0; next} {print}' It simply extracts what looks like hrefs and what looks like prices, hoping you'll get an alternating sequence of urls and prices. Then joins consecutive lines to get the format you want.


0

The best way to get at data from eBay is through their API. This being said, sometimes all you have is HTML, so I'll cover that in my answer. Don't even try to extract information from HTML with tools like sed and grep. It's hard to do when it works at all, and extremely brittle. This way lies madness. If you have to parse HTML, use a tool for parsing ...


0

Perl solution : perl -ane 'print map "$F[0] $_\n" ,split(",",$F[1])' file 1 a 1 b 1 c 2 z 3 d 3 f


0

Please try it: sild@:/tmp $ cat test 1 a,b,c 2 z 3 d,f sild@:/tmp $ cat test.sh #!/bin/bash separator="," cat test | while read line; do head="`echo $line | cut -d" " -f1`" IFS="$separator" read -ra nodes <<< "`echo $line | cut -d" " -f2-`" for i in "${nodes[@]}"; do echo $head $i done done sild@:/tmp $ ./test.sh 1 a 1 b 1 c 2 z ...


1

Awk solution: $ cat file 1 a,b,c 2 z 3 d,f $ awk '{ gsub(",", "\n"$1" "); print; }' file 1 a 1 b 1 c 2 z 3 d 3 f


2

awk 'BEGIN {first_row = 0; col_val=""}{ if (first_row == 0) {first_row = $2; col_val=$1} else {print col_val " " first_row - $2; col_val=$1}}' This is the output from the command line: $ echo "10 -0.314690785295 20 -0.251967909317 30 -0.215271387106 40 -0.189228416217" | awk 'BEGIN {first_row = 0; col_val=""}{ if (first_row == 0) {first_row = $2; ...


1

put the following lines into a script file, such ad mydownload.sh magnet=$(lynx -dump -hiddenlinks=listonly lynx_bookmarks.html | grep "magnet" | sed 's/&.*//' | cut -c 7-) curl http://my_ip:my_port_number/startdownload/${magnet} save and exit chmod 755 mydownload.sh ./mydownload.sh


1

So what you need is to capture the output of one command, and use it in another. The bash $(..) syntax will let you execute a command and capture the output, then you can use that output in another command. One way is to capture the output in a variable, such as: shortcut=$(lynx -dump -hiddenlinks=listonly lynx_bookmarks.html | grep magnet | sed ...


0

If your input is as simple as it looks, then here's a bash shell script doing the things that shell scripts are no good at: #!/usr/bin/env bash declare -a col2 while read col1 rest do IFS=, read -a col2 <<< "$rest" for value in ${col2[*]} do printf "%s %s\n" "$col1" "$value" done done < input There are better ways to do it (read -a ...


0

bash-4.1$ echo $( echo hi ) hi bash-4.1$ So, curl $( ... ) Would pass the output of whatever ... is to curl by running whatever those commands are as a subshell. $() can also be written with backticks, though those are header to read, and do not nest. grep | sed can probably be replaced with a single call to awk.


0

awk '{arr[$1]++} END {for (i in arr) {if (arr[i]==1) {print i} }}' 1 grapes lime peach


0

Or, to show all different line: sort test.data | uniq


4

That's the job for uniq: $ LC_ALL=C uniq -u file grapes lime peach If you want other tools, like perl: perl -nle '$h{$_}++; END {print for grep { $h{$_} == 1 } %h}' <file


1

Try this AWK! awk '{a[$0]++} END {for (x in a) if (a[x] == 1) print x}'


1

You can use the read shell builtin: while IFS=" " read -r value1 value2 remainder do ... done < "input.txt" Extra fields, if any, will appear in 'remainder'. The shell's default IFS (inter-field-seperator) consisting of white space characters will be used to split each line into its component fields.


1

If you have access to GNU grep: grep -vP '^(\d+-\d+-\d+|=+)$' file And, if you don't: grep -vE '^([0-9]+-[0-9]+-[0-9]+|=+)$' file Both commands use grep's -v flag which means "print lines that don't match the pattern and look for lines consisting of either 3 groups of digits separated by dashes or one or more = from the beginning (^) to the end ($) of ...


0

An alternative solution in AWK: awk -v FS="," '/^[0-9]/{line=$0;getline; line=line" "$1", "$2 ;print line}' file


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. ...


3

You can do: grep -o '[^ ]*\.swf' file.txt [^ ]* matches zero or more non-space characters \.swf matches literal .swf Example: % grep -o '[^ ]*\.swf' file.txt example.swf example2.swf example3.swf


7

With GNU grep: grep -o '\b\w*\.swf\b' file Output: example.swf example2.swf example3.swf \b: a zero-width word boundary \w: word character \.: match one dot See: The Stack Overflow Regular Expressions FAQ


3

First step Replace spaces with line ends using sed Second step Filter the output using grep Example sed -e s/\ /\\n/g file | grep .swf


0

This works with your sample awk ' NR==FNR {patt[$0]; next} $0 in patt {getline; getline; getline; prev=$0; next} {print prev; prev=$0} END {print prev} ' fileA.txt fileB.txt You have to keep all of fileA in memory, but you only need to remember one line at a time from fileB


0

Next code is not optimal (because it have to read FileB.txt twice) but hope it can be more quick then awk comm --nocheck-order -23 FileB.txt <(grep -B1 -A2 -Ff FileA.txt FileB.txt) With new GNU sed command e you can try (for memory saving) sed + grep: sed 'N;h;s/.*\n//;s/.*/grep -xF "&" FileA.txt/e;/./{N;N;d};x;P;D' FileB.txt



Top 50 recent answers are included