Hot answers tagged

4

You can do this with Ghostscript. gs \ -sDEVICE=pdfwrite \ -o marked.pdf \ -c "[/CropBox [54 54 1314 810] /PAGES pdfmark" \ -f original.pdf The cropbox must be calculated with the resolution of your PDF, reference is the bottom left corner. See also this QA.


4

It should be possible with a single awk command awk '{print $1 > $2".lst"}' xxx.lst


4

E.g.: sed -r 's:([A-Za-z])([0-9]+):\1<sub>\2</sub>:g' should do the job. (Match a letter followed by a group of digits and remember it as \1 and \2. Replace all of that by the same letter (\1) plus the digit group (\2) enclosed in the sub tag.)


4

What's probably happening is that the CPU goes into a more aggressive power-save mode. This causes the internal switch-mode voltage regulators to go into a pulse-skipping mode, moving the switching frequency down to the audible range. The noise comes from the inductors and capacitors, both being slightly microphonic (which also works in reverse; the emit ...


3

Not sure what you are doing wrong but the following works: for i in *; do cp "$i" $(date '+%Y%m%d')"$i"; done (you should only run this once in a directory)


3

On Debian or Ubuntu install stress-ng with apt-get install stress-ng. Then run: stress-ng -c 1 -l 50 playing with -c (number of CPUs) and -l (percentage load) parameters. For Fedora/RedHat/CentOS it seems you have to compile it (source repository is here) with the following procedure: wget ...


3

To avoid running one dig and read per line of the file, you could do: dig -f domains.txt mx +noall +answer Which would give an output like: stackexchange.com. 300 IN MX 5 alt1.aspmx.l.google.com. stackexchange.com. 300 IN MX 1 aspmx.l.google.com. stackexchange.com. 300 IN MX 10 ...


3

For python at least I recomend "Learn Python The Hard way", by Zed Shaw. Freely available online. Good stuff. Not sure if posting a link here is technically advertising... Here goes. Free Book


3

Since you mention there may be false positives to manually correct later, you may want to consider a slightly more robust form which incorporates the following restrictions: All chemical symbols start with an uppercase letter. All chemical symbols are either a single uppercase letter or a single uppercase letter followed by a single lower case letter, ...


3

You can use the tcl exec command, which normally collects the output, so redirect it: #!/usr/bin/expect ... exec ~/test.sh >@stdout


3

sed takes its input from stdin, not from the command line, so your script won't work either theoretically or practically. sed -i 1,10d $dr does not do what you think it does...sed will treat the value of "$dr" as a list of filenames to process. Try echo "$dr" | sed -e '1,10d' or sed -e '1,10d' <<<"$dr". BTW, you must use double-quotes ...


3

Add the /linux, /bash, /shell tags (and related ones) to your favorites on StackExchange U&L, and read the new questions and answers on a daily basis. That's how I keep up with things and learn something new every day.


3

I'd suggest doing something a bit different. Your approach is fine, but might prove annoying, when you got to do something sometime late and PC shuts down in the middle of the work. Instead, I'd suggest that you write a simple script that does something to bring your attention few minutes before shutdown, so you can prepare yourself. The simplest approach ...


3

Give this a try: #!/usr/bin/awk -f BEGIN { wordssize=split(s,words,"%"); if (wordssize==0) { words[1]=s; wordssize=1; } characterssize=0; } { if ($0 ~ /^ *[^:][^:]* *:/) { character=substr($1,1,index($0,":")-1); for (i=length(character);substr(character,i)==" ";i--){ character=substr(character,1,length(character)-1); } ...


3

virtualenv is probably what you are looking for. See http://docs.python-guide.org/en/latest/dev/virtualenvs/: A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and ...


2

if [[ -r /path/to/your/file ]]; then echo "TRUE" fi


2

You can use Vim in Ex mode: ex -sc '%s/aaa/NNN/|x' test.txt % select all lines s substitute x save and close


2

Here's a starting point for you: #!/bin/bash PHONEFILE=/path/to/your/file # Prompt for search and replace numbers # and simply exit if either is empty # (in your actual script, you'll need to flesh this out with # proper validation of phone number formats, error messages etc.!) read -p "Number to search for: " oldnum if [ ! "$oldnum" ]; then exit; fi ...


2

If you absolutely have to clean a log file, you have to do it as sudo/root and restart the syslog daemon. The adm group only lets you read but not write (some) log files. Be aware that in a Unix system a file only give up the space being used/cease to exist when it is not used anymore, hence the need for a syslog restart because if you are deleting a file ...


2

Yes setfacl should do it. Try the below, does it work ? setfacl -m u:user:--- file Where: -m is to modify the file/directory ACL user is the username for which you want to change permission --- will be the no permissions, replacing r,w,x file is the name of the file for which you want to change permissions


2

There are many. I can suggest two for python: codecademy: to learn syntax and get a basic understanding of the langauge newcoder.io: some projects to go further


2

You can do something like this: #!/usr/bin/env bash while read var1 var2; do echo "$var1" > "$var2".lst done < xxx.lst


1

Using the shell's string manipulation functions You haven't specified in which script context you intend to use this, so I'll give you a generic example: Assuming shell variable $x holds the string abc12345, then ${x:0:5} will represent the first 5 characters of $x, i.e. abc12.


1

The following is probably what you're looking for: l1=Hello l2=Hlleo count=`echo $l1|wc -m` for cursor in `seq 1 $count` do c1=`echo $l1|cut -c$cursor` c2=`echo $l2|cut -c$cursor` if test "$c1" = "$c2" then echo "true ($c1), " else echo "false ($c2 instead of $c1), " fi done


1

In case both have same character length: string_1="hello" string_2="hilda" for (( i=0; i<${#string_1}; i++ )); do [ "${string_1:$i:1}" == "${string_2:$i:1}" ] && echo "true" || echo "false" done


1

I found your problem. The -A".html" restricts it to only accepting files that end in .html. If you remove that section, you will start to download all of the files. wget -w5 -r -nd -e robots=off -U mozilla http://wwwnc.cdc.gov/travel/yellowbook/2016/table-of-contents Edit: If you want to exclude js/css/etc files, then you'd be better off using -R to form ...


1

First some comments/questions to get you thinking in a different way: (in other words, this started as a comment but became an actual answer somewhere along the way) Why are you even trying to extract the devicename element when you already know it - it's what you used to fetch the XML (with name=devicename in the URL)? Even if you didn't already have it, ...


1

.bashrc is sourced by default. -bash-4.1$ echo 'echo I was read' >> ~/.bashrc -bash-4.1$ script asdf Script started, file is asdf I was read bash-4.1$ exit Script done, file is asdf


1

Grouping and back references were the trick. Thanks for the push in the right direction. In the end, I used the following: sed 's/\([A-Z][a-z]*\)\([0-9][0-9]*\)/\1<sub>\2<\/sub>/g' file This tolerates the cases where a header, e.g. h2, occurs in the document.


1

#!/bin/bash # Array of root folders folders=("a" "b") # Search all specified root folders for f in ${folders[@]}; do # Descend hierarchy and retrieve modification date of each file with "stat" find $f -type f -exec stat -f "%m,%N" {} ';' | \ # sort by date, most recent first sort -gr | \ # extract first (most recent) file ...



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