Tag Info

New answers tagged

1

An awk solution: $ awk -F',' '$2 == 2 {$4 = "-"$4}1' OFS=',' file abc,0,def,1234,ijk xyz,2,def,-2345,abc ijk,2,def,-5678,ijl A perl equivalent: $ perl -F',' -anle '$F[3] = "-".$F[3] if $F[1] == 2; print join ",", @F' file


1

Since you're looking for words that are less than 20 characters, this includes words that are 1, 2, 3 .. or 19 characters in length (not sure if there is a word in the English language with 19 characters). The total number of possibilities is then 2619 + 2618 + 2617.. + 261. The brute force way to approach this problem is to create a list which includes ...


1

If you want words with 20 characters then with 26 letters there is 26^20 = 19928148895209409152340197376 possibilities. Computers are fast nowadays, but are they fast enough? Good luck ;)


1

Actually there is a file named /usr/share/words which contains all the English words. I would probably use that file to find all the English words and to get the words upto particular length, you can do like, awk 'length <=20' /usr/share/words | wc -l I get 479396 words inside that file.


1

It looks like the causing problem is being caused during looping of while cat /test/emailbody.txt; Remove the "," while printing in file. Following line of code has this problem: push @dzones, "No files have more than 20% deletions.\n\nPlease see attached for the deletions in different zones.\n\nThanks, Vishal\n\n";


3

The input data is kind of paragraph-oriented, so let's read it as a paragraph instead of line-by-line: awk -v RS="\n=\n" ' /PRIMER_LEFT_NUM_RETURNED=[^0]/ { n = split($0, lines, /\n/) for (i=1; i<=n; i++) { if (lines[i] ~ ...


2

You can set the record separator to \n=\n, that is a newline, a = and then a newline again. That will let you use awk as you wish: $ awk -v RS='\n=\n' -v OFS="\n" '!/PRIMER_LEFT_NUM_RETURNED=0/{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,RS}' file SEQUENCE_ID=Contig1 SEQUENCE_TEMPLATE=AAGTCGCCCCTCCAT PRIMER_LEFT_NUM_RETURNED=2 ...


1

The direct way: awk '$3 !~ "=0"{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,RS}' RS='=\n' FS='\n' OFS='\n' file This will add an extra blank line after =, you can remove it easily if you want.


0

Using os.system() in Python to get the output from calling a command is not the way to go. For single commands you can use the function check_output() from the subprocess module. In your situation I would take a look at plumbum it allows you to do things in python like: from plumbum.cmd import zcat, grep chain = zcat["your_file_name.gz"] | grep["-i", ...


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


1

Another perl perl -F, -lane 'print join ",", map {(/-$/ && chop) . $_} @F' file


0

Here are a few: A shorter perl one perl -pe 's/([\d.]+)-/-$1/g' file (GNU) sed sed -r 's/([0-9.]+)-/-\1/g' file Any sed sed 's/\([0-9.]*\)-/-1\1/g' file Gawk. Note that the various awk variants are not very good at tasks that involve capturing patterns. GNU awk (gawk) and others can do it but I would use one of the solutions above instead. gawk ...


1

Same as perl command, $ sed 's/\([0-9]\+\.[0-9]\+\)-/-\1/g' file 0.00,-70440.19,-18.31,0.00,-451.59,-13788.77,-44.19,-6289.29 -1.03,-39.24,-0.11,-16.96,0.00,-72377.70,0.00,-146673.67,-59.11,0.00 Another perl one-liner, $ perl -pe 's/([^,\n]*?)-/-\1/g' file 0.00,-70440.19,-18.31,0.00,-451.59,-13788.77,-44.19,-6289.29 ...


1

The below one worked: Any other awk or sed solution would be great to know... perl -pe 's#(\d{1,}[.]\d{1,})(-)#$2$1#'g 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] ...


4

Another awk: awk '{$1=RS $1 ORS}NR>1' FS='\n' RS=\> OFS= file


1

An awk solution: awk '/^>/{if(FNR>1)printf "\n";print;next}{printf "%s", $0}' file A perl solution, like @choroba's answer, but handling final newline: perl -pe 'chomp unless /^>/ or eof;print "\n" if /^>/ and $. > 1' file


2

perl -pe 'chomp unless /^>/; print "\n" if /^>/ and $. > 1' < File1 You might need to add the final newline.



Top 50 recent answers are included