w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to convert xml file in to a property file using unix shell script
this may help? <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="//person"> "<xsl:value-of select="name"/>" = "<xsl:value-of select="family-name"/>" </xsl:template> </xsl:stylesheet> save it as x.xslt and do xsltproc x.xslt file.xml

Categories : Xml

Unix - Shell script to find a file from any directory and move it
find / -type f -name FILENAME | xargs -I foobar echo mv foobar /tmp (remove echo to make the command actually work .. i put it there just to save yourself from accidentally moving files just to try out the command) Note that -I foobar means that in mv foobar /tmp replace the foobar string with full path of the file found. for example, try: find / -type f -name FILENAME | xargs -I foobar foobar is a cool file

Categories : Shell

Unix Shell Script get all specific string on a file and modify it vertically
Making some possibly unrealistic assumptions, this can be managed with: sed -e '/^value /!d' -e '/value/{N;N;s/ /|/g;}' data Primary assumption: When you get a 'value' line, it is followed by two more 'value' lines (there are no 'row' lines in the middle of a set of three 'value' lines). There's no need to case convert value c in the input to value C in the output. It doesn't matter what appears after the 'value' and the space (so any letters or words — indeed, any text at all — is OK after the 'value'). Strictly, the /value/ in the second -e argument is not necessary, but it emphasizes that it only processes the 'value' lines. To make this into a script, use: #!/bin/sh sed -e '/^value /!d' -e '/value/{N;N;s/ /|/g;}' "$@" The "$@" means 'all the arguments passed to the scr

Categories : Shell

Triggering a windows batch script from unix shell script
Take a look at this: http://stackoverflow.com/a/16720186/2471910 It talks specifically about invoking a windows program from another windows machine (instead of a unix machine) but the concepts are the same since ssh is available on unix as well.

Categories : Unix

Arithmetic in Unix shell Script
Use awk for this: awk '{$2=($2+$3)/2; $3=$2+1}1' file You can also use the int() function to ensure that the result is an integer: awk '{$2=int(($2+$3)/2); $3=$2+1}1' file

Categories : Shell

Unix shell script run SQL scripts in parallel
The first command should run synchronously... If you start the two last commands as background processes (add & at the end of the command), they will run in parallel. Do you want the script to wait for the two last processes to be complete before leaving? Something like this should work: sqlplus user1/pw @/home/scripts/tst1.sql sqlplus user1/pw @/home/scripts/tst2.sql & pid2=$! sqlplus user1/pw @/home/scripts/tst3.sql & pid3=$! # pseudo-code: # while (`ps -p"$pid2,$pid3" | wc -l` != "1"); sqlplus user1/pw @/home/scripts/tst4.sql

Categories : SQL

Unix shell script for increment the extension
The problem is that your while loop is executed in a subshell due to use of a pipe, so your modifications of n do not work as intended. In general, you could use process substitution with while to avoid this problem, but in the case at hand a simple for loop is the right approach: #!/bin/sh file="testfile" n=1 for i in folder/${file}* do if [ folder/${file}.${n} = ${i} ] then n=$(( $n + 1 )) fi done cp testfile folder/${file}.${n}

Categories : Bash

How to put database connection check validation in Unix shell script
Try it with the following code ... if ! db2 -x "Select A.USER_ID from USER A ,ROLE_TYPE R, USER_ROLE U where A.USER_ID=U.USER_ID AND U.ROLE_ID=R.ROLE_ID" >> $UserId then echo "there was an error, maybe the connection failed fi

Categories : SQL

Access UNIX server and run a shell script from java application
You could use SSH component JCraft for remote connection and shell commands invocations: import com.jcraft.jsch.* Exerp from my old code: JSch jsch = new JSch(); String command = "/tmp/myscript.sh"; Session session = jsch.getSession(user, host, 22); session.connect(); Channel channel = session.openChannel("exec"); ((ChannelExec)channel).setCommand(command); channel.setInputStream(null); ((ChannelExec)channel).setErrStream(System.err); InputStream in = channel.getInputStream(); channel.connect(); byte[] tmp = new byte[1024]; while (true) { while (in.available() > 0) { int i = in.read(tmp, 0, 1024); if (i < 0) { break; } System.out.print(new String(tmp, 0, i)); } if (channel.isClosed()) { if (channel.getExitStatus() == 0) {

Categories : Java

Find multiple file with name (shell unix)
How about find with -regex switch: find -E . -regex "^./(~|##)$" -exec rm '{}' ; -E is being used to support extended (modern) regular expression feature.

Categories : Shell

Unix / Shell Add a range of columns to file
One way using awk: $ awk 'NF!=n{for(i=NF+1;i<=n;i++)$i=0}1' n=9 file A B C D E 0 0 0 0 A B C D E 1 1 1 1 Just set n to the number of columns you want to pad upto.

Categories : Shell

How display one line and sort a file in unix shell?
# print the first 2 lines sed 2q file # skip the first 2 lines, join 3 lines into 1, then get unique lines sed 1,2d file | paste - - - | sort -u TAB | STAT | RECORDS ------------------------ TAB1 DUPKEY 26 paste joins with a tab character by default

Categories : Unix

Separating phrases occuring a file-Unix Shell
You can use sort for that: $ sort -u file comp1 comp2 comp3 comp4 The -u flag tells sort to only keep unique lines Or if you must use awk, you can do awk '!a[$0]++' file Answer to updated question Use this awk command: $ awk '{a[$1]=$0}END{for (i in a) print a[i]}' file comp1 : path11 comp2 : path12 comp3 : path9 comp4 : path10

Categories : Bash

Gathering Unix machine stats in Java or Unix shell
I come with a basic script handling some options. It is not an answer at all, just an approach that is too broad to post in comments: start_day=22 end_day=$1 sar_path="/var/log/sa" start_time=14 end_time=17 echo "start_day = $start_day - end_day = $end_day" echo "start_time = $start_time - end_time = $end_time" if [ $start_day -eq $end_day ]; then echo "sar -i 900 -f $sar_path/sa$start_day -s $start_time:00:00 -e $end_time:00:00" elif [ "$(($start_day + 1))" -eq $end_day ]; then echo "sar -i 900 -f $sar_path/sa$start_day -s $start_time:00:00 -e 23:59" echo "sar -i 900 -f $sar_path/sa$end_day -s 00:00:00 -e $end_time:00:00" elif [ $start_day -gt $end_day ]; then last_day=$(ls -1 $sar_path/sa[0-9]* | tail -1) last_day=$(basename $last_day | grep -o

Categories : Java

How to use TRUNC function in SQL server 2012, as am getting 'TRUNC' is not a recognized built-in function name.'?
ROUND ( 30.95 , 1 , 1 ) When the third parameter != 0 it truncates rather than rounds http://msdn.microsoft.com/en-us/library/ms175003(SQL.90).aspx Thanks to http://stackoverflow.com/a/44093/44743

Categories : SQL

How to Create Unix Script (.sh) file in C#?
There's a difference between how UNIX textfile end of line (with the single character ), and Windows end of line (with two characters and ). So in Windows there's an extra character, and this is probably what's causing your issues when the file is transferred to your Android device. The reason it works when you create the file in Notepad++ is that when you do save as .sh it recognizes it as a UNIX bash script file type and intelligently doesn't put the extra Windows character at the end of each line. But the C# code you wrote DOES put the extra character since it doesn't have that type of awareness of the output file type. You need to output your text files without that extra character, using something like the following for the write operation: File.WriteAllText(myOutputFile, st

Categories : C#

Translating shell script into Windows command shell script (batch)
for /L makes a count-controlled loop in batch. mkdir remains mkdir. @echo off for /L %%y in (1,1,9) do mkdir week_0%%y mkdir week_10

Categories : Shell

how to pass variable from python to shell script when shell script is getting called inside python script
You can: Step through the list, and then call mail.sh once for each file. This is the most reliable way. Convert the items in the list to a space delimited string, and then pass it in to mail.sh (assuming mail.sh is setup correctly, it should accept multiple arguments). What you cannot do is pass ['a.txt','b.txt','c.txt'] wholesale to the script.

Categories : Python

How to make a shell script that opens a file and adds lines at the end of the file and then saves?
To answer the question in the title, $ echo "root soft nofile 65536" >> /etc/security/limits.conf will add the line root soft nofile 65536 at the end of the file. To reboot, in many linux systems, you just have to do : $ reboot And to test a value , you could do something like : if [ "`ulimit -n`" -lt "65536" ]; then # do stuff fi So finally, your script would look like : #!/bin/sh if [ "`ulimit -n`" -lt "65536" ]; then file='/etc/security/limits.conf' { echo "root soft nofile 65536" echo "root hard nofile 65536" echo "soft nofile 65536" echo "soft nofile 65536" } >> $file reboot fi

Categories : Shell

how to fetch details from a file and store in a temporary file in shell script?
You can try this : x=($(grep -Po "(?<=DB_IP=)(.+)(?=,)|(?<=DB_NAME=)(.+)" config.txt)) y=($(grep -Eo "[a-zA-Z_]+=" details.txt)) echo $y$x > temp.txt echo ${y[1]}${x[1]} >> temp.txt Assuming that the order of DB_IP and DB_NAME is always same in both files.

Categories : Shell

Using Shell script and sed - Find and replace a word in file and rename file
I guess you are making it complex: why not make it simple with two simple satements. Its up to you how you use the below statements for your purpose: perl -pi -e 's/wordtofind/wordtoreplace' your_file #for replacing the word in the file mv your_file wordtoreplace #for renaming the file

Categories : Shell

shell script to create backup file when creating new file in particular directory
Can you explain why you want to do? Tools like VIM can create a backup copy of a file you're working on automatically. Other tools like Dropbox (which works on Linux, Windows, and Mac) can version files, so it backs up all the copies of the file for the last 30 days. You could do something by creating aliases to the tools you use for creating these file. You edit a file with the tools you tend to use, and the alias could create a copy before invoking a tool. Otherwise, your choice is to use crontab to occasionally make backups. Addendum let me explain suppose i have directory /home/pavan now i create the file myfile.txt in that directory , immediately now i should automatically generate myfileCopy.txt file in the same folder paven There's no easy user tool that could do that.

Categories : Linux

Create output file names based on input file name with autonumbers shell script linux
VAR="INPUTFILENAME" # One solution this does not use the VAR: touch INPUTFILENAME{1,2,3,4,5,6,7,8,9,10} # Another for i in `seq 1 20` ; do touch "${VAR}${i}" done And there are several other ways.

Categories : Linux

Shell script: copying columns by header in a csv file to another csv file
Just figure out the name associated with each column and use that mapping to manipulate the columns. If you're trying to do this in awk, you can use associative arrays to store the column names and the rows those correspond to. If you're using ksh93 or bash, you can use associative arrays to store the column names and the rows those correspond to. If you're using perl or python or ruby or ... you can... Or push the columns into an array to map the numbers to column numbers. Either way, then you have a list of column headers, which can further be manipulated however you need to.

Categories : Shell

Getting file through FTP using shell script
'ftp' is so 80s! Why don't you move up the foodchain a little? wget --user="${FTP_USER}" --password="${FTP_PASS}" "${FTP_SITE}/dir/files" wget supports the FTP protocol and can continue interrupted downloads, can exclude files, can do recursive retrieval and just about anything.

Categories : Unix

shell script : how to replace file name
Created using bash on a mac, so it might work with whatever shell you are using... string="/home/guest/test" echo $string | sed 's//([^/]{0,})$//.1.log/' Using simple shell string replacement wasn't going to work since I know of no way you can target the last occurrence of the / sign as the only replacement. Update: Actually I came to think of a alternative way if you know that it is always "/two/directories/in" string="/home/guest/test" firstpartofstring=$(echo $string | cut -d/ -f1-3) lastpartofstring=$(echo $string | cut -d/ -f4) echo ${firstpartofstring}/.${lastpartofstring}.log

Categories : Shell

shell script to add header to a file
You can use awk like this: awk 'NR==FNR && !h {print;h=1;} NR!=FNR{print}' headerFile mainFile > tmpFile mv tmpFile mainFile Using vim/vi: vim +'0r headerFile|wq' mainFile 2>/dev/null Using GNU sed: sed -i.bak -e '2{x;G};1{h;rheaderFile' -e 'd}' mainFile Using non-GNU sed: HDR=$(head -1 headerFile) && sed -i.bak "1s/^/$HDR/" mainFile

Categories : Shell

shell script: inserting a new line to a file using sed
The second example on the cited link is a solution for you < a.txt sed "/ABC$/a \ #define DEF " will produce from the a.txt #define ABC the output #define ABC #define DEF Or the 5th example from the above link < a.txt sed "/ABC$/s/$/\ #define DEF/" so, READ!

Categories : Shell

How to create file validation shell script?
Keeping it simple, and assuming that by "shell" you mean a Unix shell: ls -1 path/to/directory | sort > list1.txt sort file_with_filenames.txt > list2.txt diff list1.txt list2.txt You can probably tweak this into a smart loop or one-liner, but for a one-shot problem this should suffice. Upside is that you don't have to worry about spaces in filenames, which can make looping solutions rather tricky. You can use the return code from diff to break if there are any differences. Since you didn't state any specific requirements, I didn't bother with things like creating the list files in /tmp making this re-entrant (e.g. by including PID in the temporary filenames) cleaning up the temporary files afterwards do sanity checks (existence of directory / filelist etc.) "Production" qua

Categories : File

xcrun file shell script code in Mac OSX 10.7.5
To install the version of xcrun that you want you should install the corresponding version of Xcode. Go to Xcode->Preferences->Downloads->Components. Then click the button to install the Command Line Tools.

Categories : IOS

CSV file date processing in shell script
I did it in basic shell script with nanoseconds: while read line do d1=$(echo $line | cut -d, -f1) d2=$(echo $line | cut -d, -f2) ds1=$(date -d"$d1" "+%s.%N") ds2=$(date -d"$d2" "+%s.%N") diff=$(echo "$ds2 - $ds1" | bc) printf "$ds2 - $ds1 = %.3f " $diff done < file Test $ while read line; do d1=$(echo $line | cut -d, -f1); d2=$(echo $line | cut -d, -f2); ds1=$(date -d"$d1" "+%s.%N"); ds2=$(date -d"$d2" "+%s.%N"); diff=$(echo "$ds2 - $ds1" | bc); printf "$ds2 - $ds1 = %.3f " $diff; done < file 1373524748.748000000 - 1373524748.748000000 = 0.000 1373524748.826000000 - 1373524748.826000000 = 0.000 1373524748.860000000 - 1373524748.860000000 = 0.000 1373524748.919000000 - 1373524748.919000000 = 0.000 1373524748.941000000 - 1373524748.941000000 = 0.000 1373524749.39

Categories : File

Unix script to recursively search a directory and sub directories to grep and print content between 2 patterns in file
This might work for you: find . -type f -exec awk 'BEGING {print FILENAME ":"} /Pattern1/ { p=1 ; next } /Pattern2/ {p=0} p==1 {print $0} END {print ""}' {} ; Note, this prints the FILENAME, even if Pattern1 was not found!

Categories : Unix

Shell command works in shell but not in shell script
You are using single quotes in this command: filelist=$(grep '$incstring' -rl --include=*.{h,cpp} pathToFiles) Single quotes inhibit variable expansion. That is, you're looking for the literal string $incstring rather than the contents of that variable. This command, as shown here, would not have worked on the command line either. From the bash(1) man page: Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. Replace the single quotes with double quotes: filelist=$(grep "$incstring" -rl --include=*.{h,cpp} pathToFiles)

Categories : Shell

How to sort random strings in a file via shell script
Whole idea is to grep every «string» and then collapse it to single line via tr. $> grep -P -o "[0-9a-z-]+" file | sort --unique | tr ' ' ' ' ticket-125788 ticket-125948 ticket-126824 ticket-126914 ticket-126957 ticket-126961 ticket-127012 ticket-127022 ticket-127024 ticket-127030 ticket-127035 ticket-127220 ticket-127262

Categories : Bash

how to find/fetch number in a file using shell script
A=$(egrep -o '[0-9]+' my_file | egrep -c '^1') The first egrep finds all the numbers and outputs them. The second egrep uses the -c option to output the count of matches, and the regexp matches lines that begin with 1.

Categories : Linux

Directory or File contain space error in Shell Script
Classic; don't use for .. in, use find "$INDIR" -type f | while read file; do echo "Encrypting $file" "$PROJECT_DIR/crypt" -e -k $ENC_KEY -i "$file" -o "$OUTDIR/`basename "$(dirname ${file})"`/`basename "$file"`" done

Categories : Osx

shell script taking last empty line of a file also
while read LINE do [ -z "$LINE" ] && continue IMEI=$(echo $LINE | sed 's/ //g' | sed -e 's/[^ -~]//g') END_SERIAL=$(echo $IMEI | cut -c9- | sed 's/ //g' | sed -e 's/[^ -~]//g') echo "CRE:EQU,${IMEI}0,${END_SERIAL},${list},,${TODAY};" >> ${OUTFILE}i done < "${FILE_NAME}" If the line is empty, continue with the next iteration of the loop. Or have sed delete blank lines (containing blanks and tabs only) before feeding the file to the loop: sed '/^[ ]*$/d' "$FILE_NAME" | while read LINE do IMEI=$(echo $LINE | sed 's/ //g' | sed -e 's/[^ -~]//g') END_SERIAL=$(echo $IMEI | cut -c9- | sed 's/ //g' | sed -e 's/[^ -~]//g') echo "CRE:EQU,${IMEI}0,${END_SERIAL},${list},,${TODAY};" >> ${OUTFILE}i done

Categories : Linux

Shell script not redirecting correct output to a file
It all depends on what OS and version of the software you're using on but it probably boils down to this: many common commands are designed to work slightly differently depending on whether they're being called interactively or in a pipeline. (in this context, redirecting and piping would have the same results, as the command decide their behavior based on whether stdout is bound to a terminal) The most pervasive example would be ls: by default it lists files in column in interactive mode and one for per line in pipe mode. Check your man page for documented behavior with ps. You can emulate pipe mode while keeping output to stdout by piping to cat: ps -a | cat Another explanation, if you're under a weird enough shell, is that it has a builtin for ps, but doesn't wish to use it in cert

Categories : Shell

Reading data from properties file in shell script
I'm certain that the file /opt/oracle/scripts/user.properties contains CR+LF line endings. (Running the file command for the properties file would say ... with CRLF line terminators). Changing those to LF using dos2unix or any other utility should make it work. Moreover, instead of saying: conn=$username$password$service_name you could say: conn="${username}${password}${service_name}"

Categories : Linux

Using a file input as stdin for a shell script does not work
What do you need the <&1 for? Remove it, and it works. while read CMD; do ./test.sh < input.txt BEGIN get_start END get_stop END get_uknown_command END

Categories : Linux



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.