[Solved] validating IP in bash, CentOS

Presumably you have some values for regx and presumably you are having some sort of IP list function valid_ip(){ ip=$1 if [[ $ip =~ ^$regx\.$regx\.$regx\.$regx$ ]]; then return 0 else return 1 fi } 0 solved validating IP in bash, CentOS

[Solved] How to lowercase and replace spaces in bash? [closed]

Requires bash4 (tested with 4.3.48). Assuming you never want a upper case character in the value of the variable output, I would propose the following: typeset -l output output=${input// /_} typeset -l output: Defines the variable to be lowercase only. From man bash: When the variable is assigned a value, all upper-case characters are converted … Read more

[Solved] Error in shell script and how to write to a file [closed]

I think this question is fine now, the input file is good enough after edit, I can fully understand what you ask for now. With awk, you need learn to use 2-d array, it will simplify the code. awk ‘BEGIN{print “Instance id Name Owner Cost.centre”} /TAG/{split($0,a,FS);a[4]=tolower(a[4]);$1=$2=$3=$4=””;b[a[3],a[4]]=$0;c[a[3]]} END{for (i in c) printf “%-18s%-26s%-14s%-20s\n”,i,b[i,”name”],b[i,”owner”],b[i,”cost.center”]}’ file Instance id … Read more

[Solved] bash print 10 odd numbers then 10 even numbers [closed]

A simple example: echo {1..19..2}; echo {2..20..2}; echo {21..39..2}; echo {22..40..2} In a loop: #!/bin/bash i=1 while [ “$i” -lt 4000 ]; do for j in $i $((i+1)); do printf ‘%s ‘ $( seq $j 2 $((j+18)) ); echo done i=$((i+20)) done 2 solved bash print 10 odd numbers then 10 even numbers [closed]

[Solved] Linux, BASH launch command with special char [closed]

In order to configure the environment for your subsequent ant command, you have to include the “. ./setantenv.sh” inside your second call. Both calls result in independent bash processes that dont share their specific environment. try this: su – USER -s /bin/bash -c ‘cd /PATH/ && . ./setantenv.sh && ant clean all’ 0 solved Linux, BASH … Read more

[Solved] Using SFTP to transfer images from HTML form to remote linux server using PERL/CGI.pm

use CGI qw(:standard); use File::Basename; my ( $name, $path, $extension) = fileparse ( $productimage, ‘..*’ ); $productimage = $name . $extension; $productimage =~ tr/ /_/; $productimage =~ s/[^$safechars]//g; if ( $productimage =~/^([$safechars]+)$/ ) { $productimage = $1; } else { die “Filename contains invalid characters”; } $fh = upload(‘image’); $uploaddir = “../../.hidden/images”; open ( UPLOADFILE, … Read more

[Solved] Remove lines from a text file that contains multiple string patterns from another file in linux [closed]

$ cat tst.awk BEGIN { FS = “[\t|]” } NR==FNR { for (i=1; i<=3; i++) { if ($i == “”) { $i = “N.A.” } } a[$1 OFS $2 OFS $3] next } !(($3 OFS $5 OFS $6) in a) $ awk -f tst.awk file1 file2 123|234|aa|ur29842|b|c|234|567 123|234|aa|ur2909842|bb|ccc|234|567 123|234|aaa|ur29042842|bb|cc|234|567 123|234|N.A.|ur2922|bbb|cccc|234|567 0 solved Remove lines from … Read more

[Solved] How to get the sh formatter up and running?

The command is installed as $HOME/go/bin/shfmt (unless GOBIN is set, then it’s $GOBIN/shfmt): $ go help install usage: go install [-i] [build flags] [packages] Install compiles and installs the packages named by the import paths. Executables are installed in the directory named by the GOBIN environment variable, which defaults to $GOPATH/bin or $HOME/go/bin if the … Read more