Tag Info

New answers tagged

1

You are pretty close. Rather than cat you can use awk to skip the first line and print the remaining. find "${data_dir}/${river}/${gcm}/${scenario}" name \*.dat -exec awk 'NR > 1' {} + >> "${data_dir}/${river}/${gcm}/${scenario}.dat" This is a pretty empty awk script because it relies on the default behavior. No BEGIN or END and use the default ...


0

The sequence to get to the correct quote starts with the original command: perl -e 'print crypt("password","\$6\$salt\$") . "\n"' Let's add some space: perl -e 'print crypt(" password ","\$ 6 \$ salt \$") . "\n"' Let's change the vars to their equivalents: perl -e 'print crypt(" $ENV{PSWD} ","\$ $ENV{HVAL} \$ $ENV{SVAL} \$") . "\n"' The ...


0

You are probably running into the difference between login and non-login instances of bash. If bash is started as a login shell, it reads .bash_profile. If it is not started as a login shell, it reads .bashrc. You can easily check if this is the problem by starting another instance of bash from the command line (that is, just type bash and hit return) and ...


1

cat YOUR_FILE | cut -d'#' -f1 It uses # as column separator and keeps just the first column (that is everything before #).


1

You can test it (and operate on the file if test holds true) in this way: if [ $(((`date +%s` - `stat -c %Y IOstatDisk2.log`) / 60)) -ge 55 ] then echo "File was modified more than 55 minutes ago" # do something with the file... fi


2

GNU find or BSD find will do the trick for you: find <DIRECTORY> -type f -amin +55 -name \*<PATTERN>\* -print this will print all files with name PATTERN in DIRECTORY which where accessed greater than 55 mins ago.


-3

By pressing Esc key thrice, will display this message.


6

There's no substitute for benchmarking: pskocik@ProBook:~ $ time (for((i=0;i<1000;i++)); do cat<<< foo >/dev/null; done ) real 0m2.080s user 0m0.738s sys 0m1.439s pskocik@ProBook:~ $ time (for((i=0;i<1000;i++)); do echo foo |cat >/dev/null; done ) real 0m4.432s user 0m2.095s sys 0m3.927s $ time ...


10

The pipe is a file opened in an in-kernel file-system and is not accessible as a regular file on-disk. It is automatically buffered only to a certain size and will eventually block when full. Unlike files sourced on block-devices, pipes behave very like character devices, and so generally do not support lseek() and data read from them cannot be read again as ...


0

#!/bin/bash TRX_SOURCE_PATH='/src/path' DEST_PATH='/your/dest' cp $TRX_SOURCE_PATH/Bharti\ Blocked\ TRX\ Report\ \ Morning\$*@* $DEST_PATH should work


6

The glob must be left unquoted for it to be treated as a glob. The variables should be quoted: cp -- "$TRX_SOURCE_PATH"/*TRX* "$DEST_PATH"


1

You can write a tiny script to do that for you, along these lines (adjust as needed, I'm not sure I got the story right): > cat tst.sh #!/bin/bash for river in amazon niger rhine ; do for name in gfdl hadgem ipsl ; do for count in 1 2 3 4 ; do mkdir ${river}/${name}/${count} cp -a ${river}/${name}/${river}_${name} ...


1

You could simply read documentation on this vulnerability and update instructions. E.g. redhat provides extremely detailed information: Do I need to reboot or restart services after installing the update for CVE-2014-6271 and CVE-2014-7169? If your system uses exported Bash functions, restarting affected services is recommended. Affected ...


5

The problem is with your double quotes. Here you don't need to quote those hash keys as they are simple identifiers. From perldoc perldata: In fact, a simple identifier within such curlies is forced to be a string, and likewise within a hash subscript. Neither need quoting. Our earlier example, $days{'Feb'} can be written as $days{Feb} and the quotes ...


2

How many colours are supported and how to change the foreground and background colour depends on the terminal. The terminfo database is usually there to help you come up with the right sequence. Most colour terminals support the ANSI colour escape sequences to change the foreground and background colours 0 to 7. That's: set foreground colour $n: printf ...


0

Since you are using gnome-terminal there is no need to change RGB values. Recent gnome-terminal (since v. 3.12) supports true 24 bit colours (16 millions). You can set them with \e[38;2;R;G;B. For example printf '\e[38;2;100;200;200mTest\e[0m\n' If you see blue text your terminal supports 24 bit colours. However, if you wanna stick with 256 colours I ...


0

As I have found I can get all the colors by for i in {0..255} ; do printf "\x1b[38;5;${i}mcolour${i}\n"; done It is possible to change the RGB values in ~/.Xresources like this: xterm*color4: CornflowerBlue URxvt*color1 : #ff0000 URxvt*color8 : #888888 but not all terminal emulators respect this values. URXVT does, gnome-terminal doesn't


2

scp -P PORT "$(hostname).$1-dump-$DATE.backup.gz.aes" USER@HOST:"/backups/$(hostname)/" Scp supports copying files from one remote host to another, and the syntax to do that is to specify both the source and destination using the "hostname:filename" syntax: scp srchost:/src/file desthost:/dest/file Your source file has a colon in its name, so scp is ...


0

This is the one-liner that you need. No other config needed: mkdir longtitleproject && cd $_ "$_" is the last argument of the previous command.


-1

Well, you are quite new to Shell/Bash it seems, so for educational reasons, here is a solution for you, that covers your technology of choice (http://mywiki.wooledge.org/BashFAQ/001, http://mywiki.wooledge.org/BashGuide/Parameters#Parameter_Expansion) var=1 while read -r Line; do printf "%s\n" "${Line/line_/line_$var}" >> ./file-new.txt let var++ ...


0

It looks to me like you're well covered here, but what the hell: sed -et -e's/_ /\n/;P;=;D' <in | paste -'d_ ' - - - >out sed's not exactly a whiz in the math department, but sometimes friends help it cheat, and so it gets by. That transforms... line_ some text line_ some text line_ some text ...to... line_1 some text line_2 some text line_3 ...


0

By default, screen exits when the command it is running closes, as you've observed. When you start screen by itself, the command it runs is an interactive shell, which of course doesn't exit when its children do. If you want to be able to achieve something like this from another script, you could do screen -dm -S myscreen screen -S myscreen -X stuff ...


2

You are assuming that the output of who | grep jeevansai will be a single line, which is wrong. ++ who ++ grep jeevansai ++ cut -c 32-34 + ld='31 31 ' This is telling you that the command ld=`who | grep "jeevansai" | cut -c 32-34` set the variable ld to "31 31", rather than to a single number as you were expecting. Later, you try to do math on it ...


1

The bash manpage documents the -c option thus... -c string If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0. The -c option takes the next argument as a string of commands (a list in bash ...


0

For starters what you give is not a statement. It's a bunch of commands chained together through Pipes and Command substitution. grep `date +%Y-%m-%d --date='1 day ago'` /path/to/file/FILE_PREFIX_\`date +%Y%m%d --date='1 day ago'`.dsv | grep -v 'ERROR' | cut -d "|" -f 2 | sed 's/^0/27/' Let's pick them apart one by one. Command Substitution date ...


1

awk solution: awk 'BEGIN{FS="-"} ; { print $1,$2 }' file


2

Suppose we have this file: $ cat path/to/file/FILE_PREFIX_20150730.dsv 2015-07-29|0100 2015-07-30|0200 2015-07-30|0300 2015-07-31|0400 Now observe what your command (slightly fixed) does: $ grep `date +%Y-%m-%d --date='1 day ago'` path/to/file/FILE_PREFIX_`date +%Y%m%d --date='1 day ago'`.dsv | grep -v 'ERROR' | cut -d "|" -f 2 | sed 's/^0/27/' 27200 ...


1

Bash has two completion engines: a simple one that mostly only does completion of commands in command position and file names in argument position, and a fancy one that completes arguments based on the command. To get man page completion, you need the fancy one. When you start bash, only the simple completion engine is enabled. To get the fancy engine, you ...


3

You can simply use tr utility: tr '-' $' ' < filename Output: 123 zyx 234 yxw 345 xwv 456 wvu 567 vut 678 uts You can sed like this: sed 's/-/ /g' < filename Output: 123 zyx 234 yxw 345 xwv 456 wvu 567 vut 678 uts


4

POSIXly you can get the decimal value of a hex number like: hex=10 echo "$((0x$hex))" 16 And you really don't need to do all of those [ tests ]. I think the following should work: case $f7 in (EnHr|EnSt|SpJb|Chem|[BT]rTm|PmTm|HyTm) printf "\t\t\t\t\t%s%b" \ "HEX VALUE is" ":\t$f10" \ '' "inside case loop.\t\t" \ Sen ...


0

The standard in error comes from bc. It expects hex values in upper case. So instead of 0019c4ef you should pass it 0019C4EF. The hex to dec conversion can be done using without bc too- see this answer http://stackoverflow.com/a/13280173/3935925


0

For both questions, the error came from bc. 0019c4ef is an invalid hex number in bc, you need 0019C4EF for a valid hex number: echo "ibase=16; 0019C4EF" | bc 1688815 Because you used bash (also work in ksh, zsh, mksh, pdksh, posh), you can use [base#]n where base is a decimal number between 2 and 64: $ echo "$((16#0019c4ef))" 1688815 In your case, ...


0

I don't have the 50 reputation privilege to comment on the above answer https://unix.stackexchange.com/a/104008/125690, so just as a comment to Ole Tange's response: If you're using a non-bash shell you'll need to also export SHELL=/bin/bash before running parallel otherwise you'll get an error like: fish: Unknown command 'myfunc arg' fish: myfunc arg


0

If the sample input data shown is located in a file named ./in then... <in >out tr -- - \\t ...would get you two <tab> separated columns in a file named ./out. Depending on your tr, though, you might need to use a literal <tab> character in place of the last two characters. In fact, you should feel free to substitute those last two for any ...


0

You can use -s option: column -s- -t file


5

Running su invokes bash in non-login mode. Bash then reads .bashrc to configure its environment. Runing su - invokes bash as a login shell. In this mode /etc/profile is executed if it exists. Bash also searches for ~/.bash_profile, ~/.bash_login and ~/.profile executing the first file it finds. Although not documented, it appears to execute ~/.bashrc ...


2

Depending on the quantity of the logging information you're expecting to produce, it might be worth using the standard logger tool to write it to the user syslog in /var/log: 1 */8 * * * /path/to/myprog 2>&1 | logger -p user.debug -t 'myprog' Here is an example of the output written to /var/log/debug on my Debian-based system: Jul 31 00:17:09 ...


1

I would think the quickest way to do it would look something like... sed -e's/./& /g;i\' -e'<item>' \ -ea\\ -e'<tag><out>=' <file | paste -d'\0 ""' - - - ./file /dev/null This also works: ( set -- - - - - - - /tmp/file paste -d'<item> <tag><out>="' "$@" - - - - - - "$@" | sed 's/ ...


0

to get the driver for a network interface, just use : ethtool -i en0 and look for the "driver" section : root@odin ~ # ethtool -i eth0 driver: e1000e version: 2.3.2-k firmware-version: 0.13-4 Here, my driver is e1000e. Now you can rmmod your driver and modprobe it again. This will also reset the network counters, of course.


1

You can do it without loop in awk: awk '{a=$1;gsub(/./,"& ",$1); print "<item>"$1"<tag><out>=""\""a"\""}' numbers.txt Output: <item>9 3 7 4 5 4 1 6 3 2 5 5 3 <tag><out>="9374541632553" <item>5 1 2 4 3 7 4 7 8 7 9 8 4 1 <tag><out>="51243747879841" <item>3 2 0 3 0 0 9 8 8 9 6 9 1 4 ...


2

Wrap the whole scripts you want to source into a function, add local before the declarations you want to preserve and call the function at the end of the script. func () { local name="My awesome job" nowTime=`expr $(date +%s) ` lastActiveTime=`expr $(date +%s -r ~/blah.log)` local secsSinceActive=`expr $nowTime - $lastActiveTime` ...


1

Here's one way you might be able to do the whole thing in sed: sed ' h; s/./& /g; s/.*/<item>&<tag>out=/; G; s/\n\([0-9]*\)/"\1"/; ' numbers.txt


-1

How about this... cat numbers.txt | while read line; do echo $line | sed -r "s/([0-9])/\1/g; s/([0-9])/\1 /g ; s/^/<item>/g; s/$/<tag>out=\"$line\"/g" ; done Or, cat numbers.txt | while read line; do echo "<item>$(echo $line | fold -w1 | paste -s -d' ') <tag>out=\"$line\""; done


-1

I believe the syntax for making a variable local in bash is: local variable_name= I know this works for functions and am not sure how it works with multiple scripts.


1

Because both read and sed are taking data from stdin. In the while loop, you read the first line into $line. Then sed starts: you don't give it any other input so it reads from stdin, which is the output of cat numbers.txt. So sed will consume the rest of the input. And since you're still in the first iteration of the while loop, the $line variable doesn't ...


0

Here is how to do it in perl: perl -pe 'print "line_$. $_";' [file(s)] If you want to send it to a file: perl -pe 'print "line_$. $_";' [input_file] > [output_file]


3

You can use awk: awk '$1=$1 FNR' <file> $1 is the first word of each record (line in this case). FNR is the input record number (line number in this case). This command is replacing the first word of each line with the first word + line-number of each line.


2

From man bash -c If the -c option is present, then commands are read from the first non-option argument command_string. If there are arguments after the command_string, they are assigned to the positional parameters, starting with $0. So you can do x-terminal-emulator -e bash -c 'echo $0 > ...


0

In bash -c 'echo $1 > ~/text', $1 was expanded in bash -c process, not in your script. You need to pass the original $1 to bash -c: x-terminal-emulator -e "bash -c 'echo \$1 > ~/text' bash $1"


1

You can convert the answer back into something sensible result_in_hex=$(printf "%x" $(( ~ 0x33 )))



Top 50 recent answers are included