Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

1
vote
1answer
43 views

How can I run a script recursively in a directory

I am using the following code to decode JPEG-compressed DICOMs. find ./* -maxdepth 0 -name '*.dcm' -printf 'dcmdjpeg %p %p \n' | sh I run this code inside any folder containing those files. The ...
10
votes
6answers
679 views

How to extract a key value pair from ps command

I am trying to extract application name from ps command: ps -af -u sas |grep "java"| grep -v "grep" above command produces the following: sas 24431 1 0 Oct10 ? 00:51:08 ...
0
votes
1answer
53 views

How to replace symbol || with |“”| using sed

I have a file that uses | as a delimiter. Some of the records have empty cell as || (nothing inside). I am trying to replace them with |""| with following sed command: sed -i 's/\|\|/\|""|/g' file ...
0
votes
1answer
304 views

Null message body; hope that's ok

I have the following command below as part of a cronjob. When I run the command via cron or at the command line, I get Null message body; hope that's ok. The contents of the email are empty but when ...
1
vote
2answers
49 views

Append a file, output to screen and redirect from stderr all at once, without tee

I'm running a time dd command in a shell script, and I'd like to output the results to a file, and print it out on the screen. The line that I'm currently running is: (time dd of=$dest_filepath ...
0
votes
1answer
34 views

evaluating a string in csh

script1 is as follows #!/bin/csh echo $* $* Then I run the following on command line: >script1 setenv VAR "/user/path" \; ls It gives output as: setenv VAR /user/path ; ls setenv: Too many ...
5
votes
3answers
262 views

Use bash's read builtin without a while loop

I'm used to bash's builtin read function in while loops, e.g.: echo "0 1 1 1 1 2 2 3" |\ while read A B; do echo $A + $B | bc; done I've been working on some make project, and ...
4
votes
2answers
381 views

Run script in a screen

I want to run a bash script in a detached screen. The script calls a program a few times, each of which takes too long to wait. My first thought was to simply open a screen and then call the script, ...
0
votes
1answer
116 views

SSH over multiple server and save output of multiple commands in file on local server

I want to SSH over multiple server (host 1, host2 and host 3) and save output of multiple commands (cmd1, cmd2 etc) in file (output.properties) on local server. I know there are a few posts similar to ...
1
vote
2answers
56 views

Expect script: How to handle two processes?

I am using Expect to automate VoIP calls for quality measurements. My script is calling another VoIP client for a given amount of times. Before the calls should be handled, tcpdump should sniff all ...
1
vote
1answer
81 views

Another unterminated 's' command

I am trying to make a simple replacement for an IPv4 address script. sed "s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/192.100.100.100/g" This is what I have. As stated in the title I ...
4
votes
4answers
458 views

extract every nth character from a string

I am trying to figure out a solution for this question. My approach to this problem so far is as below. Append all the characters together to make it a long string. After the above step, remove ...
3
votes
2answers
117 views

How to add new lines from another file with sed

I'm trying to find the sed command so that I can put filename into filename1. These are my two separate files. INPUT filename has: Cindy 11 22 54 Chester 48 12 84 INPUT filename1 has: Name ...
0
votes
2answers
65 views

Bash Script using read needs to stop executing on Ctrl+D

I need to write a script that will add a line to a text file if Enter is pressed. But, if Ctrl+D is pressed, I need to exit that loop in the bash. touch texttest.txt LINE="0" while true; do read ...
-8
votes
2answers
52 views

How to create my arbitary output? [closed]

How can I write a shell script that give me following output: Today is: Thursday, November 05, 2014 The IP for localhost.localdomain is: 192.168.141.140
1
vote
1answer
84 views

Summing by common strings in different files

I have a file file1 with the amount of times a user shows up in the files, something like this: 4 userC 2 userA 1 userB and I have another file file2 with users and other info like: userC, degree2 ...
1
vote
2answers
258 views

Motion start sequence - shell script modification

I've tried to modify this script to start Motion using the following libraries. I start the script by entering the following command into terminal: sudo /etc/init.d/motion start Which Gives: ...
2
votes
1answer
46 views

Unexpected result when using command line arguments to look for file with symbol

I'm trying to write a script that accepts 2 command line arguments e.g. one a directory name the other a symbol (any symbol can be $,£,^,* and so on). It should then check if the directory has a file ...
2
votes
2answers
46 views

Unzip into directory, independent if directory is contained in ZIP

Let's assume I've a ZIP file whichs content may look like # file: with_out_dir.zip file1.txt file2.cpp file3.js some_sub_dir/ - file_in_subdir.txt file4.xml but it may also look like this # file: ...
1
vote
2answers
69 views

assign output of a c program to a shell variable: token error

I have a shell script to run several times a .c program ('switch') which admit 3 input paramenters. I want to run the program 4 times passing values {4,16,32,64}, and for parameters ...
3
votes
3answers
341 views

Better way to run single for loop instead of two for loops

This works but the way I did this is kind of silly. Is there a better way to do this? for e in $(ipcs | awk '{print $2}'); do [[ "$e" = "Semaphore" ]] && break echo $e ipcrm shm ...
-1
votes
1answer
56 views

syntax error: unexpected end of the file

#!/bin/bash #organization: Seneca College #Purpose: Validate a date #Usage: chkdate year month day # year=$1; month=$2; day=$3; extra=$4 if [[ "$year" == "" || "$month" == "" || "$day" == "" ]]; then ...
2
votes
1answer
70 views

can't execute a command even i'm in the group and command is -rwx--x---

I'm in $ORACLE_HOME/OPatch directory and when I type opatch then I get the response as, -bash: opatch: command not found If I do ./opatch, then I get the response as, /bin/sh: ./opatch: ...
-1
votes
1answer
47 views

how to select multiple exit

I'm new to bash scripting and I don't understand what's wrong with this specific part of my script. im trying to select all the exit that have in my script. and trying to put in conditon that if all ...
1
vote
1answer
110 views

shell for loop with find with filenames containing spaces [duplicate]

Consider a directory with typical Microsoft Windows filenames: New Document.txt Foo.doc Foo - Copy.doc I'd like to do something on each file such as: for sendfile in $(find ${POLLDIR} -type f ...
0
votes
2answers
81 views

Bash Mysql Command Substitution Login Failure

Bash and MySQL versions: GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu) mysql Ver 14.14 Distrib 5.5.37, for debian-linux-gnu (x86_64) using readline 6.2 I have a bash script that tries ...
2
votes
2answers
212 views

Bash not equal string comparison

Why does this cause an infinite loop? #!/bin/bash while [[ "$(ipcs | awk '{print $2}')" != "Semaphore" ]]; do #Gonna get rid of the echo after working echo "$(ipcs | awk '{print $2}')" #I wanna ...
0
votes
1answer
579 views

Bash if statement [: missing `]' error [duplicate]

I am having trouble with bash. I am trying to put a command in an if statement and then compare it to a string. This works perfectly. echo $(ipcs | grep Shared | awk '{print $2}') When I put it in ...
2
votes
4answers
94 views

replace several comma out side one or more sets of curly braces and exception that in one or more sets of curly braces

In the text file I have multi records. Every record has multi column with comma separated, some column have one sets of curly brace and other have more than one curly brace. I need: If a comma is ...
0
votes
0answers
29 views

Why are my directories and files created with bashscripts ending with \r? (Script Example) [duplicate]

Okay so I'm really confused but that is cause I know next to nothing about bash scripting. My problem is when I get the script to work it creates directories and files with the \r ending and that ...
1
vote
3answers
328 views

bash script that reads user input and uses “cal” command to validate dates

I want to write a script that reads my input (for example if my script is called "check", then I would type "check 9 4 1993" and that input would go through the cal command and will check through the ...
1
vote
0answers
34 views

Get path of currently marked file

Im running OS X and I'm wondering if there is a way to get the path of the currently marked file in Finder. Like, can UNIX determine what file i have clicked on? Reasons for this would be for ...
6
votes
2answers
618 views

How do I delete all of a set of files in a random order?

I have a set of files, all that are named with the convention file_[number]_[abcd].bin (where [number] is a number in the range 0-size of drive in MB). i.e there is file_0_a.bin, file_0_b.bin, ...
1
vote
1answer
42 views

View timestamp for CUPS print jobs

I'm looking for a way to view the timestamp of a job in CUPS. I've searched the man pages and can't seem to find it. The long term goal is to have a script that parses the time from the jobID and ...
2
votes
4answers
76 views

How to remove part of a string

I keep reading the sed documentation and lots of posts but can't seem to figure this out. I have a large number of Java files. In those files are calls to a method that take the enumeration converted ...
-1
votes
2answers
90 views

Edit a file in /etc using shell scripting?

How do I use sed to edit the file /etc/heat/heat.conf? I want to add the new lines under the default section [DEFAULT] rabbit_host =controller rabbit_password =RABBIT_PASS
-3
votes
1answer
49 views

How to use Sed to replace all characters in between colons

How to replace all characters between colons using sed? # replace easy with 123 sed:easy:abc -> sed:123:abc # replace hardest with 123 sed:hardest:efg -> sed:123:efg # replace magnificent ...
12
votes
2answers
605 views

How does awk '!a[$0]++' work?

This one-liner removes duplicate lines from text input without pre-sorting. For example: $ cat >f q w e w r $ awk '!a[$0]++' <f q w e r $ The original code I have found on the internets ...
2
votes
4answers
296 views

Passing wildcard * to a (bash?) script [duplicate]

I want to to remove all color codes which look like '@n', '@R' etc, from a moderately large size collection of text files. So in a file called 'remove_cc', I wrote the following: sed -ie 's/@r//g' ...
0
votes
0answers
22 views

running graphics based script with disabled desktop environments on system startup

I'd like to introduce first what I am trying to achieve. I am having a Linux script which requires graphical environment OR which is graphical(I am myself not sure what I am trying to make others ...
1
vote
2answers
51 views

A script for making another script deal with all files in sequence?

I have found a nicely working script to convert pdf files into txt format, with ocr. But it converts only one pdf file each time. I need to mass-convert them. I have no knowledge of script ...
1
vote
1answer
103 views

Regex works in shell but not through Perl script

I'm having trouble executing a Perl script through the Unix shell using Perl's system command. I've had more complex regex commands I had to adjust accordingly to convert from Unix to Perl, and ...
8
votes
2answers
567 views

How to non-invasively test for write access to a file?

In a shell script, how do I easily and non-invasively test for write access to a file without actually attempting to modify the file? I could parse the output of stat, but that seems really complex, ...
2
votes
1answer
225 views

How to remove file log with file name

Assume, I have log files with this name format. NameLog.log.2014-09-27 NameLog.log.2014-09-28 NameLog.log.2014-09-29 NameLog.log.2014-09-30 NameLog.log.2014-10-01 NameLog.log.2014-10-02 ...
1
vote
1answer
58 views

Replace new lines char (^M) in all files and then rename file based on char string

I am not a UNIX guy but understand enough to gin up small scripts here and there except for this one where I may personally be not able to devote enough time. I have about 2000 files in a directory ...
-1
votes
2answers
282 views

Using 'sed' to find and replace [duplicate]

I know this question has probably been answered before. I have seen many threads about this in various places, but the answers are usually hard to extract for me. I am looking for help with an ...
5
votes
9answers
1k views

Decoding URL encoding (percent encoding)

I want to decode URL encoding, is there any built-in tool for doing this or could anyone provide me with a sed code that will do this? I did search a bit through unix.stackexchange.com and on the ...
2
votes
1answer
188 views

Read two text files, concatenate each line

I have two text files of the same length, in order: one of products, the other of comparison products. I'd like the output to be "product;comparison" for each line. Yes I could throw them in a ...
0
votes
3answers
165 views

How to run a script in multiple instances ? ( Ubuntu server )

How can I run a script in multiple instances in Ubuntu server? For example, I have a long running script named scanner.sh placed in /usr/bin/, which I wish to run the script in 10 parallel ...
1
vote
2answers
71 views

A tiny and simple script fail and this is the output “No such file or directory”

The script is: #!/bin/bash IFS=" " command="ls /tmp" for file in `$command`; do echo $file done And the output is: $ ./test.sh ./test.sh: line 17: ls /tmp: No such file or directory