Tag Info

New answers tagged

1

awk variables are just used for their values, like variables in most languages - they aren't re-parsed for expressions. You can do what you want with this: a='15986327,415532694,850257614,875121642,20140819' echo $a | awk -F, -v OFS=, '{print $1, $2, $4}' (setting OFS so you get commas in the output). If having b as a variable is required, you can use: ...


3

You don't need to use variable ba, try: $ echo $a | awk -F',' '{print '"$b"'}' 15986327,415532694,875121642 With this, $b is expanded by the shell, not by awk. And the rest of awk statement is not affect, because they're enclosed in single quote.


0

You can see the host, time, locations and git branch with: HOST='\033[02;36m\]\h'; HOST=' '$HOST TIME='\033[01;31m\]\t \033[01;32m\]' LOCATION=' \033[01;34m\]`pwd | sed "s#\(/[^/]\{1,\}/[^/]\{1,\}/[^/]\{1,\}/\).*\(/[^/]\{1,\}/[^/]\{1,\}\)/\{0,1\}#\1_\2#g"`' BRANCH=' \033[00;33m\]$(git_branch)\[\033[00m\]\n\$ ' PS1=$TIME$USER$HOST$LOCATION$BRANCH You could ...


4

stty and older versions of who am i will issue error messages when they're not connected to a tty device. stty checks stdin (fd 0); I don't know what file descriptor who checks. To avoid getting those error messages, the usual workaround has been to use the -t option of test (more commonly known as [) to check if the shell is connected to a tty. if [ -t 0 ] ...


0

If you ping the URL, that will give you a response as well ping -c 5 www.google.com Where -c will count until the timeout of 5 expires. In light of what I have been advised, nmap may work if you have it's package installed on your system. curl would be a better option, but nontheless here is an example using nmap: nmap -p 80 -sT www.google.com


1

You can do the following #!/bin/bash read -p "URL to check: " url if curl --output /dev/null --silent --head --fail "$url"; then printf '%s\n' "$url exist" else printf '%s\n' "$url does not exist" fi The if statements are not necessary though, I put them here just to illustrate the flow of the script.


1

curl -Is http://www.yourURL.com | head -1 You can try this command to check any URL.Status code 200 OK means that the request has succeeded and the URL is reachable. You can also test URL availability and get the response code using telnet command telnet www.yourURL.com 80 80 is the port number.


3

Your script, at the first time is using who not whoami. Change it and you should get the result you expect.


1

Thanks to @StéphaneChazelas - I was able to get my PS1 prompt exactly the way I want it. I remove the customizations from my .profile file, and appended the following to my .envfile. I was not aware of this, but the .envfile is processed after the .profile file. #set the prompt to include the date and time set -o allexport unset _Y _M _D _h _m _s eval ...


0

If on a GNU system, prefer to use stat instead: printf "Are you sure you want to copy %s (y/n) ? (file bigger than 10 MB : %s) " "$0" \ "$(exec stat -Lc '%s' -- "$0")" -L makes stat follow symlinks.


0

I assume this is in some form of shell like bash or ksh. X is the file (I also supposed it has space in its name) printf "Are you sure you want to copy %s (y/n) ? (file bigger than 10 MB : %s) " "$x" \ $(ls -ld -- "$x" | awk {'print $5'}) should do. Please note the $( some code ) syntax.


2

printf "Are you sure you want to copy %s (y/n) ? (file bigger than 10 MB: %lu) " "$0" \ "$(wc -c < "$0")" parsing the output of ls is not reliable (and you've forgotten the $(...) around it).


0

You could install Cygwin on your Windows server. If you are trying to push files to your windows host you will need to install and setup cygwin sshd on your windows host. Or you could just pull files to your windows host.


0

I would put some work into seeing if you can actually have one version with command that work on both systems. I had this issue with my .bashrc file which I keep in my dotfiles repository. I want it to work on both OSX and Ubuntu and there were a few command I had to modify to do that. In this case it was mostly which switches worked for certain command or ...


0

The easiest way by far is to use the same shell on both systems. Just because one shell is preinstalled (there's no such thing as a “default shell” for scripts, the shell is whatever the shebang line says) doesn't mean that you can't install others. You can install bash on AIX (from the toolbox, for example), or ksh93 for Linux (with your distribution's ...


1

It would probably be easier to have two separate versions of the script. Since it is short it may not be worth adding extra code to handle the differences between the two formats as jw013 suggested. On the other hand if you had a larger script it would probably be easier to have one and make the script execute different commands depending on where it is ...


3

You can use the literal newline in PS1: PS1="$_timedhms > [USERNAME]MACHINE:${PWD#$HOME/} $ " or using $'\n' with ksh93: PS1="$_timedhms$'\n' [USERNAME]MACHINE:${PWD#$HOME/} $ "


1

AIX sed does not understand escape sequence characters, as the AIX sed document said, it only know ASCII characters. So you should use another tools. tail tail -c +4 old.java > tmp.java awk awk '{NR==1{sub(/^\xef\xbb\xbf/,"")}1' old.java > tmp.java


8

The weird string "@(#)" is actually used by the ancient SCCS version control system. Specifically, the what command would look through a file (binary or text) and find ASCII-Nul-terminated strings that started with "@(#)", and print that string out. That allowed you to embed printable ASCII version numbers in ".o" files and ultimately executables, so you ...


0

For those who may stumble upon a similar problem: the zip file had been processed by Maven, which attempted to use filtering. As per the Maven documentation, this filtering can corrupt binary files. After excluding zip files from Maven's filtering, unzipping worked fine.



Top 50 recent answers are included