[Solved] Shell scripting to find the delimiter

To count the number of columns with awk you can use the NF variable: $ cat file ABC|12345|EAR PQRST|123|TWOEYES ssdf|fdas,sdfsf $ awk -F\| ‘NF!=3’ file ssdf|fdas,sdfsf However, this does not seem to cover all the possible ways the data could be corrupted based on the various revisions of the question and the comments. A better … Read more

[Solved] Separate a row of strings into separate rows [closed]

Python Power Unleased : import csv,sys filename=”a.csv” with open(filename,’rb’) as csvfile: reader = csv.reader(csvfile,delimiter=”,”) try: for row in reader: if row[1].find(‘,’) == -1: line=”,”.join(row) print line else: for i in range(0,row[1].count(‘,’)+1): line = row[0]+’,’+row[1].split(‘,’)[i]+’,’+row[2].split(‘,’)[i] print line except csv.Error as e: sys.exit(‘file %s, line %d: %s’ % (filename, reader.line_num, e)) solved Separate a row of strings … Read more

[Solved] Multiply text file in Unix by a constant

This might be close, using Perl: perl -pe ‘s/([+-]?[0-9.]+)/$1*19.123456789123/ge’ YourFile Sample Output -4894.92001617493 -4894.96925301402 -4914.3031850202 -4952.55012214707 -4971.67357651707 That kind of says… “capture anything that starts with an optional plus or minus and has a bunch digits and decimal points and call it capture group 1. Replace that with whatever it was multiplied by your magic … Read more

[Solved] Bash – back tick invocation blocks for ever

if the call to callee.sh is hanging with parameters, try executing it outside the script with parameters and check if it is hanging there as well… Anyways, the best way of saving output (and printing it out afterwards): result=”$(./callee.sh param1 param2 param2)” echo “${result}” <— this should show the line breaks 1 solved Bash – … Read more

[Solved] Finding the modules where changes were checked with svn

Three separate tasks: call svn properly to create the log parse the log Write the parsed values somewhere 1. import subprocess as sp svn_url = “svn://repo-path.com/project” revisions = [12345, 12346] revision_clargs = [“-r%i” % revision for revision in revisions] popen = sp.Popen([“svn”, “log”, “-v”] + revision_clargs + [svn_url],stdout=sp.PIPE,stderr=sp.PIPE) out,err = popen.communicate() 2. input_ = “”” … Read more

[Solved] what does this shellscript do? [closed]

This script deactivates swap obtains the amount of RAM in bytes mounts a ramdisk equal to available RAM writes zeros to the ramdisk via dd Attempts to set the dd process to be first on the chopping block for the Out Of Memory killer prints the process ID of dd and its current status for … Read more

[Solved] shell – remove numbers from a string column [closed]

You should have been more clearer when you raise the problem. Do not add test cases later You can try this, I have modified the third field to last but one. But credit to @Kaz ~> more test SER1828-ZXC-A1-10002 SER1878-IOP-B1-98989 SER1930-QWE-A2-10301 SER1930-QWE-A2-10301 SER1930-QWS_GH-A2-10301 SER1930-REM_PH-A2-10301 SER1930-REM-SEW-PH-A2-10301 SER1940-REM-SPD-PL-D3-10301 ~> awk -F- ‘BEGIN { OFS=”-” } { sub(/[0-9]/,””,$(NF-1)); … Read more

[Solved] How to commit a shell command via Java [closed]

You can use like this (netstat is only dummy command. you can write whatever you want) ; String command = “cmd.exe /c start ” + “netstat”; Process child = Runtime.getRuntime().exec(command); after that you can get as data stream from child process. Or you can close the cmd also with child.destroy() method forexample. 1 solved How … Read more

[Solved] Pass variable as options to curl in shell script linux [duplicate]

You need to use an array, not a regular variable. curl_std_opts=( -k –header ‘Content-Type: application/json’ –header ‘Accept: application/json’) curl “${curl_std_opts[@]}” -X POST –data “{\”actual\”: $BAL}” “$websiteurl” For safety, you should use a tool like jq to generate your JSON rather than relying on parameter interpolation to generate valid JSON. curl “${curl_std_opts[@]}” -X POST –data “(jq … Read more

[Solved] what is the signal *) means in linux shell

There is no *), the * is part of the pattern. The syntax of a shell case statement is: case WORD in PATTERN) COMMANDS;; esac in your case: WORD is “`uname`” : Name of the operating system, like “Linux” or “CYGWIN_NT-5.1”. PATTERN is CYGWIN*: CYGWIN followed by any number of any characters COMMANDS is cygwin=true: … Read more