New answers tagged

1

sed 's/abcd\(X[0-9][a-z]ad\)45das/\1/g' your_file_name should do it.


5

sed does not understand \d. You can use [0-9] or, more generally, [[:digit:]] in its place: $ sed -r 's/.*(X[[:digit:]])(.*)45.*/\1\2/' test.txt X1yad X2fad X3had X4wad X5mad


0

You sed does not understand the special sequence \d. Replace \d with [0-9] or character class [:digit:]: $ cat file.txt abcdX1yad45das abcdX2fad45das abcdX3had45das abcdX4wad45das abcdX5mad45das $ sed -nr 's/.*(X\d)(.*)45.*/\1\2/p' file.txt $ sed -nr 's/.*(X[0-9])(.*)45.*/\1\2/p' file.txt X1yad X2fad X3had X4wad X5mad


0

Looks like your work can be reduced to: perl -e ' use POSIX qw(strftime); my ($start, $num) = (30_000_000, 10_000); my @all = ( $start .. $start + $num -1 ); # 10,000 numbers my @odds = grep { $_ % 2 == 1 } @all; my @evens = grep { $_ % 2 == 0 } @all; my $filename = strftime "%Y%m%d", localtime; my $fh; open $fh, ...


1

For the record, you could also do this with sed: sed -s '$!N /.*PATTERN.*\n/{/\n.*PATTERN/{x;/^1$/!s/.*/1/;b v};//!{x;/^1$/{s/./0/;b v};//!D}} //!{${/PATTERN/{x;/^1$/{b v}}};D;};: v;x;P;D' file1 file2 ... fileN That's gnu sed. With other seds you'd have to process one file at a time: sed '$!N # if not on the last line pull in the next ...


2

I'll use the same test file as thrig: $ cat file a pat 1 pat 2 b pat 3 Here is an awk solution: $ awk '/pat/ && last {print last; print} {last=""} /pat/{last=$0}' file pat 1 pat 2 How it works awk implicitly loops over every line in the file. This program uses one variable, last, which contains the last line if it matched regex pat. ...


2

One way would be to save the previous line, and print when the current and previous line both match: bash-4.1$ (echo a; echo pat 1; echo pat 2; echo b; echo pat 3) a pat 1 pat 2 b pat 3 bash-4.1$ (echo a; echo pat 1; echo pat 2; echo b; echo pat 3) | \ perl -nle 'print "$prev\n$_" if /pat/ and $prev =~ /pat/; $prev=$_' pat 1 pat 2 This will ...


-2

Hi there are various command which can help you fine last line try this.. <grep command> | tail -1 or awk '/result/ { save=$0 }END{ print save }' filename


2

You can enumerate the directory contents as follows: my @files = <*.xml>; # or: my @files = </your/path/to/*.xml>; foreach my $file (@files) { $twig->parsefile($file); }


0

Definitely we can use awk, try this one awk -v RS="END" '$0~/Frankfurt/{print $0 RS}' file


1

Not sure awk is the correct tool for that job since your search is over multiple lines based. I would think it's a job for perl. Going through your file you can use (similar to your awk statement): if (/^START/ .. /^END/){} in there you store your lines in an array, that you're going to print if say Frankfurt is met (use a boolean here): push @lines, $_; ...


3

This is a perfect use case for ex, the POSIX-specified tool of choice for file editing. (If you've ever used vi, by the way, you are likely familiar with ex since everything you type in vi that starts with a colon : is an ex command. ex is the predecessor of vi.) printf %s\\n 'g/NAME#AAAA/ /AGE/t- | s/^/#/ | /AGE/s/.*/AGE NIL/' x | ex input.txt If you ...


1

perl -pe 'BEGIN{$/=""} s/^(NAME#AAAA.*\n)(AGE.*?)(\n+)$/#$2\n$1AGE NIL$3/s' ex1 very brief explanations: For all the registers in input | perl -p separator= one or more empty lines | BEGIN{$/=""} do: | substitute | s/ | ^(NAME AAAA.*\n)(AGE.*?)(\n+)$ | ...


1

You can use Vim in Ex mode: replace string ALF with BRA in all files in the current directory? for CHA in * do ex -sc '%s/ALF/BRA/g' -cx "$CHA" done do the same recursively for sub directories? find -type f -exec ex -sc '%s/ALF/BRA/g' -cx {} ';' replace only if the file name matches another string? for CHA in *.txt do ex -sc ...


0

There are various ways of doing this: Use find: find . -type f -name "*.jsp" \ -exec perl -pi.13.04.2016 -w -e "s/\b1800 102 6022\b/1860 266 2666/g;" {} \; If you're using bash, use extglob: shopt -s globstar perl -pi.13.04.2016 -w -e "s/\b1800 102 6022\b/1860 266 2666/g;" **/*jsp Do the whole thing in Perl, iterating over the files in the ...


1

Use find command to do that, find /xxx -name '*.jsp' -exec perl -pi.13.04.2016 -w -e "s/\b1800 102 6022\b/1860 266 2666/g;" {} \;


2

You can do this with awk, keeping track of numeric versus non-numeric columns and summarizing at the end: #!/usr/bin/awk -f BEGIN { width = 0; } { if (width < NF) width = NF; for (n = 1; n <= NF; ++n) { if ( $n ~ /^[0-9]+$/ ) { number[n] += $n; total[n] += 1; } else { others[n] ...


1

When your are manually running the ssh command, I assume you have configured password-less ssh and ~user/.ssh has the necessary keys. When running this via web page, the ssh is executed as user apache (or user httpd) and ~apache/.ssh is used for the keys. That user does not have password-less ssh so "Permission Denied". You are viewing the web-page from ...


2

To replace Helloby Hii you could use: s/Hello/Hii/ tr works different. Using tr both character sequences are handled as lists. The first character of the first list is replaced by the first character of the second list. So, H is replaced by H, e is replaced by i and so on.


0

To answer your title question, you can join consecutive lines like so using sed: sed 'N;s/\n/ /' /tmp/glog.lst However, your column issue is really a separate question entirely. The best solution to that is, go upstream to the tool that generates your glog.lst file and make it use some sensible delimiter rather than whitespace. If that's completely ...



Top 50 recent answers are included