FAQ Database Discussion Community


Shell script rename and move files from one folder to the other

bash,file,shell,unix
I am very new to Unix. I have a folder with files of format ABC-DEF-Somestring.100-03-06-2015 ABC-DEF-Somestring.200-03-06-2015 Need to move it to another folder with filenames as ABC-DEF-Somestring.100-04-06-2015 ABC-DEF-Somestring.200-04-06-2015 What is the easiest way to achieve this...

schedule automate shell script running not as ROOT

python,linux,shell,unix,linux-kernel
I have a shell script that I want to run automatically every day at 08 AM, and I am not authorised to use the crontab because I don't have root permission My home directory is /home/user1/. Any suggestions?...

How to remove characters before and including an underscore?

linux,string,bash,unix,awk
In bash scripting what's an efficient way to do the following please? var="fooo_barrrr" What is the best way to remove all characters before and including the '_' so that var becomes "barrrr" please?...

Can not connect to an abstract unix socket in python

python,c++,sockets,unix,unix-domain-sockets
I have a server written in c++ which creates and binds to an abstract unix socket with a namespace address of "\0hidden". I also have a client which is written in c++ also and this client can successfully connect to my server. BTW, I do not have the source code...

How to create a new file where each new line contains some text and quoted line/step number?

shell,unix,command-line,awk
I want to use a loop while creating a new file where each new line is created by one/single step: some text, then quoted step number, and then something else. I started with this code, but it does not work: gawk ' { for (i = 1; i <= 1000;...

Replace a double backslash followed by quote (\\') using sed?

regex,shell,unix,sed
I am unable to replace double backslash followed by quote \\' in sed. This is my current command echo file.txt | sed "s:\\\\':\\':g" The above command not only replaces \\' with \' it also replaces \' with ' How could I just replace exact match? Input: 'one', 'two \\'change', 'three...

Struct member selected from type, it is not visible and will not be selected

unix,ocaml
I have a function that uses the Unix lib for its time functions: let rfc822 (t: Unix.tm) : string = Printf.sprintf "%s, %s %s %d %s:%s:%s %s" (List.nth short_days t.tm_wday) (padInt t.tm_yday 2 "0") (List.nth short_month t.tm_mon) (t.tm_year + 1900) (padInt t.tm_hour 2 "0") (padInt t.tm_min 2 "0") (padInt t.tm_sec...

How to open a new terminal from my working terminal with same directory in Linux?

linux,unix,ssh
Is there any command to open a new terminal from my working terminal with same directory while working with ssh in Linux? e.g., I am working in the following terminal. My pwd is /home/work/Kayan01/test_run I want to open a new terminal directly from my working terminal, so that the pwd...

How to replace newlines/linebreaks with a single space, but only if they are inside of start/end regexes?

regex,linux,shell,unix,replace
I have an extremely big (many GBs in size) file that looks like [x data1 data2 data3 data4 y] [a data5 data 6 data7 data 8 b> [x data y] ...and so on How to replace newlines (which might be surrounded by spaces) with a single space, but only if...

Random password generate in shell script with one special character

bash,shell,unix,random,passwords
I have following code </dev/urandom tr -dc 'A-Za-z0-9@#$%&_+=' | head -c 16 which is randomly generating password perfectly. I want two changes: It should only contain 1 special symbols that i have listed there It should choose random length of the password I tried with length = $(($RANDOM%8+9)) then putting...

Find the maximum values in 2nd column for each distinct values in 1st column using Linux

linux,bash,unix,awk
I have two columns as follows ifile.dat 1 10 3 34 1 4 3 32 5 3 2 2 4 20 3 13 4 50 1 40 2 20 What I look for is to find the maximum values in 2nd column for each 1,2,3,4,5 in 1st column. ofile.dat 1...

Mounting GEOM_ELI Encrypted ZFS Pool as root

unix,encryption,freebsd,boot,zfs
I have a 3 Disk RAIDz1 Pool, encrypted with AES128 in GEOM_ELI, that I have been using in FreeNAS since version 8. There have been many zpool upgrades, and over all I am very happy with ZFS. Lately however I have been growing frustrated with FreeNAS. Largely many bugs that...

Extracting columns within a range AWK

unix,awk
I've been trying to extract lines where a number in one columns falls within a particular range. Lets say I have a file that looks as so: chrom prediction chrom1 0.75 chrom2 0.5 chrom4 0.76 If I wanted to print lines where the prediction value was in the range from...

Blocking in pthread_join()

c,multithreading,unix,pthreads
According to the manual page: The pthread_join() function shall suspend execution of the calling thread until the target thread terminates, unless the target thread has already terminated. So, as I understand, the calling process will block until the specified thread exit. Now consider the following code: pthread_t thrs[NUMTHREADS]; for (int...

nano: Move forwards/backwards one word with META+Left / META+Right

unix,terminal,nano
One can move forwards / backwards one word using Ctrl+Space and Meta+Space respectively. How can I bind META+Left arrow to move backwards one word / META+Right to move forwards one word? Thx for helping....

Delete numbers from filename

shell,unix
I have a bunch of file names of the type: a-1.001.txt a-2.234.txt a-3.765.txt and so on. I want them to be: a-1.txt a-2.txt a-3.txt This is all in unix. I've been trying with "rename" but I can't get it to work with regular expressions. (I've read there are two versions...

how to break one column into multiple columns in Linux [duplicate]

linux,bash,shell,unix,awk
This question already has an answer here: split a column in multiple columns 3 answers I want to break a column into different rows. e.g., test.dat 1 4 3 4 6 2 4 6 8 What I want is to break it into a 3 x 3 matrix out.dat...

How to convert following text in required format in unix?

unix,awk
I have a file which has the following format: 1 2 3 4 5 6 I am trying to make it like: 1 2 3 4 5 6 I have tried awk 'BEGIN { ORS= " "} {print}' test.txt It makes 1 2 3 4 5 6. But I need...

Calling find more than once on the same folder tree

linux,bash,shell,unix,find
I'm running a find command multiple times on the same group of files. The results of my find commands are usually disjoint sets, AKA I'm running find -mmin +35; find -mmin -25, and doing different things to the results. It seems sort of silly to search through the entire file...

How to extract single-/multiline regex-matching items from an unpredictably formatted file and put each one in a single line into output file?

linux,shell,unix,replace,grep
I have a very huge file which looks like this: <a>text</a>text blah <b>data1</b>abc<b>data2</b> <b>data3</b>blahblah <c>text</c> <d>text</d> <x>blahblah<b>data4 data5 data6</b> <b>data7 </x> That is, its formatting is unpredictable. I need to extract each <b>...</b> item (it might contain multiline text!) and put every one of them in a single separate line....

What does signal(SIGPIPE, SIG_IGN); do?

c,unix,signals
I know the individual uses of SIGPIPE and SIGIGN. What does signal(SIGPIPE, SIG_IGN); exactly do?...

Converting values from for loop to json format

linux,unix
Below is a snippet of a for loop where I sort txt file names. I am then trying to save the results in a json format file. However it results in an invalid json format due to the last , inserted in obj. How could i convert to json format...

How to find average and maximum in an interval using Shell [closed]

linux,bash,shell,unix,awk
I would like to extract sum, mean and average in each 6 numbers interval from a column. I found many discussions related to this problem, but all those are for whole column. e.g. To compute sum of a column: awk '{sum+=$1} END { print sum}' To calculate Average: awk '{sum+=$1}...

search value and count number from log file

linux,bash,perl,shell,unix
I've value in the logfile as below and I want to catch all the same number and count them and put in another file every 10 minutes. How can we do that ? [14/06/2015 14:33:55.311] - WARNING- Conflict detected between two sources !!! id1=67 id2=69 number=1193046 [14/06/2015 14:33:55.607] - WARNING-...

Effect of umask on text files

linux,file,unix,permissions,umask
I understand how umask works, at least a basic level, when dealing with the permissions of an executable file or directory. However, I struggle when it comes to how umask applies its rules to text files. For example, consider the umask 037. On newly created executables or directories I understand...

Path of the current, parents and root directory

shell,unix,sed,path,pwd
I need to print the path of the current, parent and root directory in UNIX. I can use commands, or a shell script. I managed to do that for the current and the parent directory, but I do not know how to print it for the root directory. Here is...

Split a column's values into multiple rows awk/unix/python

python,unix,awk
Here is a sample row of input data : header: id,indicator,{(pid,days_remaining)} row: id_558314,1,{(property_66021,7),(property_24444,1),(property_285395,6)} Expected output of data : header: id,indicator,pid,days_remaining row1: id_558314,1,property_66021,7 row2: id_558314,1,property_24444,1 row3: id_558314,1,property_285395,6 Is this something easily doable using awk/unix/python? Thanks in advance. Your time and help is appreciated....

Join Statement omitting entries

unix,join,hidden-characters
Using: Unix 2.6.18-194.el5 I am having an issue where this join statement is omitting values/indexes from the match. I found out the values are between 11-90 (out of about 3.5 Million entries) and I have tried to look for foreign characters but I may be overlooking something (Tried cat -v...

C programming bi directional communication

c,unix,multiprocessing,ipc,inter-process-communicat
I am trying to make something work here, i have c program where my parent process creates a pipe so he can listen request from children process. These children are created dynamically, it is never the same number. So far, i managed to send the requests to the parent through...

searching through text file in terminal

linux,unix,awk,grep,less
Hi this might be a basic question for many, but it has however managed to eat a couple of hours of my time. I have large data file as an output from running a script. The file contains around 15 columns and around 100,000 rows. I wish to search through...

Bash Scripting - AWK with Delimiter?

bash,unix,awk
I've got a header in a text file that looks like this: First-Name:Last-Name:City:Home-Phone:Cell-Phone What I need to do is display the Last-Name and the Cell-Phone number of each entry. I'm new to bash scripting, and I'm not really sure what I can use to do this. I was told awk...

Use Unix Executable File to Run Shell Script and MPKG File

osx,shell,unix
I have 2 shell scripts and 2 mpkg installer, I am trying to use an unix excitable file to run them all. here is the script I have, but it always has error message "No such file or directory" ? #!/bin/sh # Find the absolute script current path path=$( cd...

Why can I view some Unix executable files in Mac OS X and not others?

git,bash,shell,unix,binary
I am on a Macbook Pro on Mac OS X 10.10 (Yosemite). When I go to /usr/bin, git is there as a unix executable file. When I open it up in Sublime Text, all I get is unreadable machine code. However, when I open up a different Unix executable file—in...

Doubts with for loop in Unix

bash,shell,unix,for-loop
Sorry if its sounds dumb but I'm currently studying for an exam to apply for a job (administrative one) and I learnt about java, php, python but not much about unix scripts. I can see it's very similar to php in structure and I have many questions about it ....

Regular expression find command cygwin?

regex,linux,unix,find,cygwin
I've never been able to get regular expressions in Cygwin to work for me. Here's some background info: -find (GNU findutils) 4.5.12 I have the following files in my directory: -rw-rwxr--+ 1 None 0 Jun 4 19:16 eiooo.txt -rw-rwxr--+ 1 None 0 Jun 4 19:20 g.py -rwxrwx---+ 1 None 96...

Why is Unix/Terminal faster than R?

r,bash,shell,unix,terminal
I'm new to Unix, however, I have recently realized that very simple Unix commands can do very simple things to large data set very very quickly. My question is why are these Unix commands so fast relative to R? Let's begin by assuming that the data is big, but not...

A unix system programming project on windows?

c,unix,posix,system
I was given a unix prgramming project (with of cours a use of signal handling and fork()) but i have some issues with my ubuntu and i prefer to work on windows. So is there a solution ? I installed Cygwin but i don't think it will be enough to...

How to grep for value in a key-value store from plain text

linux,shell,unix,grep
Given a plain text file containing FOO=foo BAR=bar BAZ=baz How do we grep for the value using the key?...

does a publicly available partial solution exist to parse *nix-style command line options without pre-knowledge of the keys? [closed]

linux,bash,shell,unix,command-line
does a publicly available partial solution exist (in any language) to parse *nix command line options into a data structure in the case where the option keys are not known in advance. basically, parse something like my-script -x ex --y=why zebra and get {'x': 'ex', 'y': 'why'} without knowing that...

recursively replace echo value with previously echoed value in Unix [duplicate]

linux,bash,shell,unix
This question already has an answer here: How to show and update echo on same line 2 answers I want to print a loop like below a=0 while [ $a -lt 100 ] do echo ${a}% a=`expr $a + 1` sleep 1 done It throws output as follows 1%...

man pages for c variable types

c,unix,man
Are there any Unix man pages or similar standardized reference for variable type declarations (in c)? For example, if I want details on the float variable type and different ways to declare it, is there a standardized reference in Unix? The compiler man pages? Or is an online reference or...

Bash - Script that reads .txt file and stores the info in variables to be used later

bash,shell,unix,network-programming,network-interface
I'm working on a bash script that must be able to create "network interface profile configurations", store them in any kind of file (.txt I guess) and then, if called with parameters, eg: ./myscript eth0 myprofile must execute the commands in myprofile.txt to configure that network interface. So, right now,...

Bash script to configure network interfaces

linux,bash,unix,network-programming,network-interface
I'm a network and OS student, and I have to make a script that does the following: It can be called with or without parameters. If called with parameters, it must recieve the name of a network interface (e.g: eth0) and a "name of a configuration profile". Well, I am...

What is wrong with these formats for Unix Shell Scripting Comparing Strings [duplicate]

bash,unix
This question already has an answer here: bash output command not found 4 answers I've been reading through StackExchanges posts on scripting and none of the things that I have tried are working as I would expect. Also this is my 1st shell script. # Script File Begin echo...

series of commands using nohup [duplicate]

shell,unix,nohup
This question already has an answer here: Why can't I use Unix Nohup with Bash For-loop? 4 answers I have a series of commands that I want to use nohup with. Each command can take a day or two, and sometimes I get disconnected from the terminal. What is...

My JSch session doesn't execute command

java,unix,jsch
I'm trying to write a Java code that can ssh into a Unix server and reset a user's password. So I tried to implement some of the code found in SO. Eg. Sending commands to remote server through ssh by Java with JSch Take commands(password) from string and set as...

SFTP Processbuilder

java,unix,sftp,processbuilder,ssh2-sftp
I have to invoke unix commands from Java and I have to use ProcessBuilder. I want to login through SFTP using key authentication and I want to SFTP the file from local directory to remote location. ProcessBuilder pb = new ProcessBuilder("sftp","-oIdentityFile=privateKey","-b","commands.txt","username@hostname"); Content in commands.txt is put localFileDirectory remoteDirectory exit Is...

how to check a directory exist and can write file

oracle,shell,unix,sql-loader
I need to check directory test_file exist, if yes then need to check directory test_file is having write permission so that files will be writen in the same. this functionality i needed in shell script(ksh). What would be return code from sqlldr for single table load and multi table...

`fs.mkdir` is creating the directory with different permissions than those specified

node.js,unix,permissions,fs
Due to the modules my node program uses, it requires root to run. This is because it has to run a HTTP server on port 80 (and as you know, lower ports like that require root in order to be used). But, this program also uses a fs method to...

Running custom program located in /bin

linux,unix,path,bin
I have created a folder ~/bin. This is my own bin to store my own custom programs. As a test, I wrote a simple hello world program. I export using PATH=~/bin:$PATH so that Linux looks in that directory. If I save hello (my test program name) I can successfully run...

Output of SQL query and command to a file in shell script

bash,shell,unix,cron
I have the following shell script which runs a SQL query and a command which sends the output as an email. The issue is I am able to send only the SQL output. Not the output of the for loop. I tried to give the "EOF" after the for loop...

Unix: Where does “ls -l” get comma-separated values in size field for devices?

c,unix,ls
When I run ls -l /dev on OS X I get an output with the following format (but many more files): crw-rw-rw- 1 root wheel 4, 126 Jun 11 20:28 ttywe crw-rw-rw- 1 root wheel 4, 127 Jun 11 20:28 ttywf As far as I can tell, it is specific...

Zip all subdirectories using python

python,linux,unix,ubuntu
I am attempting to create a script that zips all of the subdirectories of a folder, then deletes the folders which have now been zipped import shutil import os loc = "foldertzipfilesin" path = "/whereparentis/" + loc + "/" dirs = os.listdir( path ) for file in dirs: name =...

How to make zero the entire row except the first column, if it has a zero in any other colum in Linux?

linux,bash,shell,unix,sed
I would like to make zero the entire row except first column, if it has a zero value in any other column. e.g., ifile.txt 1 4.5 9 2 5.0 0 3 2.4 4 4 3.1 2 5 0.0 0 6 2.4 1 7 0.0 5 I am looking my output...

Multiple line search in a file using java or unix command

java,shell,unix,command
I want to find the following pattern in a file like subclass "Pool1" 11:22:33:44:55:66 { dynamic; } the above pattern I have to find in a file. How can I find either using java or Unix command?...

Implementation of copyout() in FreeBSD

unix,freebsd,bsd,netbsd
Where is the definition of function copyout() in FreeBSD for AMD64? (http://www.unix.com/man-page/FreeBSD/9/copyout/) The only place I can find is in sys/sys/systm.h. The definition/declaration is: int copyout(const void * __restrict kaddr, void * __restrict udaddr, size_t len) __nonnull(1) __nonnull(2); Is it a declaration or a definition? What does __nonnull(1) and __nonnull(2)...

Capture tee's argument inside piped Perl execution

perl,unix
How to capture piped command's argument ? I use : perl my_script.pl -some_args | tee arg_filename How to get arg_filename 's value inside my_script.pl ? CONTEXT I need to send this filename in a mail which my_script.pl sends at the end. I need to use tee because we dump huge...

C - does read() add a '\0'?

c,unix,io,posix,unbuffered
Does it have to? I've always been fuzzy on this sort of stuff, but if I have something like: char buf[256]; read(fd, buf, 256); write(fd2, buf, 256); Is there potential for error here, other than the cases where those functions return -1? If it were to only read 40 characters,...

What does mean the @ (at) on unix access right?

php,unix,web,ls,access-rights
I have looked but it seems I did not found any question like mine. I would like to know what does mean the @ (at sign) on UNIX repository like as follow: MacBook-de-Blouz:twentyfifteen ratinahirana$ ll total 1136 -rwxrwxrwx@ 1 ratinahirana staff 376628 28 oct 2014 screenshot.png -rwxrwxrwx@ 1 ratinahirana staff...

C++ Compile error on NetBSD '::system' has not been declared

c++,unix,boost,g++,netbsd
I have some C++ code that compiles nicely on Linux but so far I'm having trouble getting it to compile correctly on NetBSD. These are my includes: #include <fstream> #include <iostream> #include <cstdlib> #include <unistd.h> #include <iomanip> #include <boost/regex.hpp> I compile with this command: g++ -v -O2 -fno-strict-aliasing -I /usr/pkg/include...

Identifying when a file is changed- Bash

bash,shell,unix
So in my bash shell script, I have it running through a for loop. Inside the for loop, I use find "$myarray[i]" >> $tmp to look for a certain directory each time through the loop. Sometimes, it finds the variable in myarray[i] and sometimes it doesn't. When it does find...

Scala Process for Linux is stuck

scala,unix,process,cat
I'm trying to use Scala Process in order to concate two files and send the result to a new file. The code works fine, but when i remove the permissions to the folder, it seems to be stuck. Here is the code: val copyCommand = Seq("bash", "-c", "cat \"" +...

Unix c program to calculate pi using threads

c,unix,pthreads
Been working on this assignment for class. Put this code together but its giving me several errors I'm not able to solve. Code #include <stdio.h> #include <stdlib.h> #include <pthread.h> //global variables int N, T; double vsum[T]; //pie function void* pie_runner(void* arg) { double *limit_ptr = (double*) arg; double j =...

ImageMagick - Making 2 GIFs into side by side GIFs using IM convert

image,unix,imagemagick,imagemagick-convert
I have 2 GIFs that are the same length. I want to put the GIFs beside each other to have 1 GIF with both playing at the same time. I have tried to use the convert tool with: convert +append 1.gif1 2.gif output.gif However, this seems to blend all the...

Copy file into multiple directories - Unix

linux,bash,unix,directory,directory-structure
I want to copy one file into many directory. My path structure is like above. folder1-> anotherfolder -> **here I want to copy my file** folder2-> anotherfolder -> **here I want to copy my file** folder3-> anotherfolder -> **here I want to copy my file** folder4-> anotherfolder -> **here I...

wc -l on unix command return value

linux,shell,unix
I have a program that when I run it it takes away comments and blank lines etc. /home/user/Development/loc -c /vobs/unitTestStub/works.h And it prints out comment stripped code like #ifndef works_H #define works_H #include <fc.h> #include <stdlib.h> #include <unistd.h> ... When I run a wc -l /home/user/Development/loc -c /vobs/unitTestStub/works.h It prints...

Selecting unique lines based on two columns

unix,awk
I've been trying to figure out a way to select lines that are unique based on the values of two columns. For example, here is a sample/example of my file: chr1 10 12 chr1 10 12 chr1 10 11 chr1 9 12 chr2 15 20 And this is what I...

apache with virtual hosts: 403 forbidden

osx,apache,unix
I know, this problem has been faced several times, but after reading many posts, it still does not work. the funny part: yesterday it worked. so, who can help me find the error? step by step: I am using Apache/2.2.29 on Mac OS 10.8.5 /etc/hosts 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1...

pass enter key from Java to Shell script

java,unix,jsch
I am trying a Java program to run multiple commands in unix environment. I would need to pass 'ENTER' after each command. Is there some way to pass enter in the InputStream. JSch jsch=new JSch(); Session session=jsch.getSession("MYUSERNAME", "SERVER", 22); session.setPassword("MYPASSWORD"); Properties config = new Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); Channel...

Where is the cupsctl terminal executable on MacOSX?

osx,shell,unix,find,cups
I've looked everywhere, and can't seem to find cupsctl anywhere. I assume it's a lot like echo or sh, it's just an executable with a PATH variable sat somewhere on the system. In order for me to call an NSTask from an Obj-C app I'm working on, I need to...

Kill command in UNIX

linux,bash,shell,unix,ubuntu
If I execute the Following command all the process will be killed and the account is logged out. Command: kill -9 -1 It is similar to the logout command. In Unix, no such process having the pid as "-1". So, what is the reason for this result?...

storing 'du' result in a variable [duplicate]

bash,unix,putty
This question already has an answer here: How to return the output of program in a variable? 4 answers I am using Putty with bash-4.2. Therein, I am outputting file size with: du -m myfile.csv which returns: 1.25 myfile.csv How do i store this line in a variable so...

Unix - Tail Utility would open the file or not

unix,logic,tail
Can anybody help me to sort this out. What is the logic of Tail -f utility in Unix. Is it open the log file to check the updated content or is there any other way to get this information. All the implimentation of Tail utility says that it will open...

gzip and pipe to output (performance consideration)

linux,unix,encryption,gzip,solaris
q1) Can i check if I do a gzip -c file | encrypt (some parameters) a) does gzip print out the output line by line and pipe it to the encrypt function or b) gzip will be perform 1st, then the output will be pipe all at once to the...

Modern-day Unix tools are written in what programming language? [closed]

c,linux,bash,unix,grep
Here is an example of using two Unix tools: ls | grep "MMC" ls and grep are two Unix tools. I believe that both ls and grep are written in C. (Correct me if I'm wrong) What programming language is used to implement modern-day Unix tools? Are modern-day Unix tools...

Improving a sort program's efficiency; displaying column sort % completion in terminal

python,perl,sorting,unix
I have a big pipe-delimited input file approx 6 million lines as below: 24|BBG000SJFVB0|EQ0000000009296012|OI SA-ADR|OIBR/C|US|ADR|Equity 16|BBG002PHVB83|EQ0000000022353186|BLOOM SELECT INCOME FUND|BLB-U|CT|Closed-End Fund|Equity -50|BBG000V0TN75|EQ0000000010271114|MECHEL-PREF SPON ADR|MTL/P|US|ADR|Equity 20|BBG002S0ZR60|EQ0000000022739316|DIVIDEND 15 SPLIT CORP II-RT|DF-R|CT|Closed-End Fund|Equity -20|BBG001R3LGM8|EQ0000000017879513|ING FLOATING RATE SENIOR LOA|ISL/U|CT|Closed-End Fund|Equity 0|BBG006M6SXL2|EQ0000000006846232|AA...

how to ssh run a tail and then send data to a mysql database

linux,bash,unix,ubuntu,ssh
This code SSH's and then runs a tail command on a remote hots. I would now like to pass that tailed data into a mysql database using a local script called insertPerfmon.sh. How do I pass data generated in a ssh session into the local shell script insertPerfmon.sh. The local...

awk — adding a new delimiter to the default space delimiter

unix,awk
awk default delimiter space treats any amount of space between two fields as equivalent.. echo "1 2"|awk '{for (i=1;i<=NF;i++) print $i}' #which gives the result (two spaces between 1 and 2) 1 2 How can I add "=" to this existing delimiter? I have tried the following and that has...

C std library don't appear to be linked in object file

c,osx,unix,objdump,otool
I am using a program like this with math.h function "sin" and stdio.h function"printf" used #include <stdio.h> #include <math.h> int main () { int x = sin(14); printf("hello"); return 0; } And as stated by ephemient here that libc.so and libm.so (for math functions) should have been linked with the...

Enumerating executable files in C

c,unix,directory,ansi
I am trying to enumerate only files with the execute (+x) bit set. My code seems to list all files. It also seems to enumerate directory and the above directory which I do not want. Example: .. should_not_be_executable.sh . Is there a way to filter '..' and '.' without strstr()?...

How to send message (in C) from one thread to another?

c,multithreading,unix,pthreads
I'm trying to send a message from one thread to another. Each thread knows the thread ID of the other. How can I send a message between them? I've already seen some proposed solutions (message queue, anonymous pipe, etc.) but honestly I didn't get them to work. Obviously I didn't...

awk if statement with simple math

unix,awk,gawk
I'm just trying to do some basic calculations on a CSV file. Data: 31590,Foo,70 28327,Bar,291 25155,Baz,583 24179,Food,694 28670,Spaz,67 22190,bawk,4431 29584,alfred,142 27698,brian,379 24372,peter,22 25064,weinberger,8 Here's my simple awk script: #!/usr/local/bin/gawk -f BEGIN { FPAT="([^,]*)|(\"[^\"]+\")"; OFS=","; OFMT="%.2f"; } NR > 1 END { if ($3>1336) $4=$3*0.03; if ($3<1336) $4=$3*0.05;}1** Wrong output: 31590,Foo,70...

Disregard word order when comparing two variables

shell,unix,sh
I want to compare two variables using shell. $a="abc pqr mno xyz" $b="mno pqr xyz abc" Here two variable values are same (just words order is not same inside the variable). If i compare $a and $b it will say that $a and $b are not same, but I want...

How to search for a text in specific files in unix

unix,grep
I am using Ubuntu machine and tried with below commands to search for a text: This command to check if the word is present in a given directory recursively: 1) Here <hello> is the word which I am search for and it searches recursively in all files starting from current...

Bash script to email when wc -l count is below 3

linux,bash,unix,wc
Please, can you help me with a script that counts something (wc -l) and when the count is below 3 the script emails me. Thank you!...

Difference on bash and ash parentheses

linux,bash,shell,unix,ash
I was trying to use a diff command for comparing directory listings which works fine in bash: diff <(cd alpha ; find . -type f) <(cd beta; find . -type f) However, on the ash (embedded device where no other shell is available) I get -ash: syntax error: unexpected "("...

How to perform parallel processes for different groups in a folder?

bash,unix,parallel-processing,groups
I have a folder containing a lot of images. I have a code which transforms these images into black and white format and then use tesseract to convert them into text files. I have been using the following code to split these files into subgroups: i=0; for f in *;...

Reading rsync source from file results in improper parsing of file names with white space

bash,shell,unix,scripting,rsync
I wrote a simple script that searches through a specific directory defined by the variable "SCOPE" producing a list of directories that were modified within the past 24 hours printing them to a temp file. The first line of the file is deleted (to exclude the root level of the...

Redirect output from file to stdout

bash,shell,unix,stdout
I have a program that can output its results only to files, with -o option. This time I need to output it to console, i.e. stdout. Here is my first try: myprog -o /dev/stdout input_file But it says: /dev/ not writable I've found this question that's similar to mine, but...

find numbers divisible by 3 in csv file using shell script

bash,shell,unix,awk
I have csv file having content like below : 1|2|3 4|5|6 7|8|9 Now I would like to find the numbers which are divisible by 3 using shell scripting. I would like to use awk command for this. I am learning shell scripting. So could you please help me out to...

Is setting environment variable through a makefile - possible?

c,unix,makefile,malloc,gnu-make
I'd like to take advantage of MALLOC_PERTURB_ environment variables that can change memory allocation parameters (man 3 mallopt). However, I'd like to control allocation parameters on application level, not entire system level. Ideally, if I could control them through project's makefile. I've tried to change mentioned variables through makefile, yet,...

Redirect Outward of unix os commands to html page

linux,unix,command
How can i redirect and export unix os commands to HTML Page?

^M behind operating system version?

linux,windows,unix,operating-system
I am currently writing a perl script to extract data from a log file and create statements using the data in a new file. In this new file, one particular data that I've extracted and used here is the operating system's version. It shows Windows XP Service Pack 3^M. I...

How can I configure and allow pipes in my bash script?

bash,unix
I'm a beginner writing Bash scripts so I'm confused on the architecture of pipes. For the basic commands such as grep for example, did pipes have to be somehow configured and programmed to be allowed into the command? Or do pipes just automatically pass in the outputs as the first...

How to fix btrfs root inode errors

unix,fsck,btrfs
Running btrfsck, or more officially, btrfs check --repair gives this output stating that there are root inode errors. The repair command does not fix the issue and reruns will display the same output. The system is fully mountable and operational, but I cannot perform advanced operations on the partition (resizing)....

Send alert for 80% threshold comparing two values from Disk partition

linux,unix,ubuntu,storage,diskspace
Need send a alert comparing two values of disk space for all partition It should check for SIZE and USED values and compare values makesure not more than 80% Filesystem Size Used Avail Mounted /dev/sda1 9,9G 3,3G 6,1G / none 17G 213k 17G /dev none 17G 0 17G /dev/shm none...

How to do the expansion of variable in shell script? [duplicate]

linux,bash,shell,unix,ksh
This question already has an answer here: Bash expand variable in a variable 4 answers I hava a column in database which contains the following data: sql_proc|test_sql.sql|/home/Desktop/myfile.txt|$IMP_FILES/myFolder|convert I have fetched this into a variable and I have used the cut command with "|" as delimiter and saved each field...

Replacing alternate spaces with newline?

unix,replace
I am trying to replace the alternate spaces with newlines using UNIX. I tried using tr command in UNIX but was unable modify it to replace alternate spaces. Sample input: 0 1 2 3 4 5 Sample output: 0 1 2 3 4 5 How do we achieve this ?...

Grep a gzipped file?

unix,gzip
I would like to see if there is a title url in the following gzip file: curl -O http://www.imdb.com/sitemap_US_02002.xml.gz grep 'imdb.com/title/tt' sitemap_US_02002.xml.gz Is there a way to do this 'on the fly', perhaps even in a one-liner?...

Unable to connect to mysql after automating mysql-server installation in bash script

mysql,linux,bash,unix
Generates a random string: passdb="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-2};)" Feeds passdb to debconf i.e to set random passwords for mysql users: debconf-set-selections <<< 'mysql-server mysql-server/root_password password $passdb' debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password $passdb' apt-get -y install mysql-server It get's installed successfully but I'm getting an error after...