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

learn more… | top users | synonyms (2)

-1
votes
2answers
76 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
47 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
563 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
236 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
21 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
44 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
82 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
543 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
208 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
51 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
108 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
7answers
806 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
134 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
115 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
61 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
1
vote
1answer
57 views

ffmpeg script - slicing a video into multiple slices

I am currently using ffmpeg to slice video files. I automated the process through a script called ffmpeg_split.sh. To view the script click here. When I run the script I have an error when trying to ...
-2
votes
1answer
59 views

How to use `cal` to run scripts? [closed]

I wrote a script and need to make it run with the cal command. How do I do this? This is my .bashrc: PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/lib/ast/bin:/home/$USER/bin:.
9
votes
4answers
274 views

Unexpected EOF and syntax error

I am currently writing my third ever shell script and I have run into a problem. This is my script so far: #!/bin/bash echo "choose one of the following options : \ 1) display all current users \ ...
2
votes
2answers
68 views

Add Text to Command Line via Shell Script

I have a shell script which is opening different terminals. After opening the terminals, I manually start different applications in the terminals. I would like to automate this by adding text (e.g. ...
3
votes
2answers
78 views

How can I run a script when internet connection is about to get lost?

I use wvdial (PPP dialer) with sim card modem and sometimes this connection is reset by server side. I would like to run a script which greps ifconfig to get a volume of data downloaded and stores it ...
4
votes
3answers
172 views

Script to compare 2 input paramters and show shared letter(s)

I am writing a script that I want a user to enter two separate words, and the result to show which letter the two words share. For instance ./share Cat Rat - would return shared letters: "a" and "t". ...
0
votes
2answers
61 views

Find and for loop

Trying to do a mass convert from M4A to OGG in a large music collection, I have: #!/bin/sh for i in `find /home/family/Music -name *.m4a -print0` #do ffmpeg -i "$i" -acodec libvorbis -aq 6 -vn -ac ...
4
votes
2answers
131 views

When is 'if' not necessary?

In some scripts, I've seen if conditional statements written as: if [ some_conditional_statement ]; then # do stuff fi or [ some_conditional_statement ] && #do stuff Is the second ...
2
votes
1answer
48 views

bash_logout only run command on last logout

This command is in my .bash_logout script to delete a temporary directory when I logout after running some processing: /bin/rm -rf /tmp/tmpdir/ However, I usually have more than one connection to a ...
0
votes
1answer
57 views

Command to list all usernames on a Linux server

What is the command that allows one to generate a list of all the usernames of authorised users on a Linux server? I have tried getent passwd | cut -d : -f 1 | xargs groups and less ...
3
votes
3answers
219 views

How to copy, execute and retrieve data from a remote computer?

I am trying to run some calculations on a remote computer. Basically I want to copy some files to the computer, load a software, execute the calculation, then retrieve the data back. I have created a ...
2
votes
2answers
102 views

How to get grep exit code but print all lines?

I'd like to check whether a line printed by a command contains an error message, but I'd like to also print all the output from the command (for make logs). Is there some way to get all the output of ...
2
votes
2answers
131 views

Shell script to merge files with same names

I have a directory of files such as: file.1111111_1.pdf file.1111111_2.pdf file.2222222_1.pdf file.2222222_2.pdf … file.1234567_1.pdf file.1234567_2.pdf … file.aaaaaaa_1.pdf file.aaaaaaa_2.pdf … ...
3
votes
1answer
134 views

Finding largest file recursively

I am trying to find the largest file in a directory recursively. If there is a subdirectory inside of that directory the function needs to go inside that directory and check to see if the largest file ...
0
votes
1answer
81 views

Very basic H/W question using pipe and grep

I have two text files, F1a.txt and F1b.txt, with essentially the same data: the driver's surname and their nationality. For example: Hamilton GBR Alonso SPA I have concatenated these ...
-2
votes
1answer
2k views

convert CSV to XLS file on linux [closed]

The following Perl script can convert CSV file to XLS file the problem is that I need to install on customer Linux machine many Perl modules in order to run this Perl script , and actually I cant ...
0
votes
1answer
125 views

Using Grep Colour to look in a file, and output with a coloured answer in amongst the file contents

I am currently in the process of writing a program in raspberry pi that will allow me to look inside files and have what I entered displayed in colour I think I need to do something to do with ...
5
votes
1answer
84 views

How to end a shell script?

I'm partway writing a script on Linux and I wanted to add an extra bit and ask the user whether they want to quit the program, can anyone help me in figuring out how I can do this?
0
votes
3answers
153 views

How does the following shell script work in finding all files larger than 20MB?

I came across a post advising that the following will find all files greater than 20Mb in size. find / -type f -size +20000k -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }' | ...
1
vote
1answer
47 views

Run Comand on all files (folders ad subfolders) [duplicate]

All, I have a lot of PDF files. Does there exist a way to apply to all PDFs in folder and sub-folders at one time? Example, I have: /pdf/test/pdfa.pdf /pdf/example/aa/test.pdf I'd like to apply ...
0
votes
1answer
82 views

SSH to a server, execute update command that continues even after logging off the ssh session

Okay I saw a lot of questions like this, but almost all have either theoretical answers which do clear the concept but I am still not able to put it up in code. What I want to achieve using a bash ...
0
votes
2answers
32 views

Using a file as an input to a script

Say I want to use the name of a file as input, and process it with a pre-made script in a certain directory. How do I do it? fileName < /folder1/scriptName is this the right format?
1
vote
3answers
100 views

Input two numbers and add them when “a” is typed, subtract when “s” is typed

So I'm having a little trouble with this code. When i try to execute I get the message line 12: 0: command not found #!/bin/bash let results=0; echo "First number please" read num1 echo ...
0
votes
2answers
47 views

check two partitions by selecting random files and running sha1 hashes on two files of each partition

A previous answer to a post mentions to run sha1 hashes on an images of a dd drive clone image. Another answer to that post suggests mounting the dd image an then compare if the sha1 hashes of ...
1
vote
2answers
83 views

run grep cmd recursively and print path name and result

I have a log file that exists in multiple directories one for each client. I am trying to run the following: find . -iname "20140926.log" -exec cat {} \; | grep 123456 | grep 'food="100"' | wc -l ...
0
votes
2answers
30 views

merge mutiple files using common column [duplicate]

Say I have multiple files x1, x2,x3,x4, all with common header date, time, year, age. How can I merge them to one singe file X in shell scripting? File x1: date time year age 101014 1344 2012 52 ...
2
votes
4answers
92 views

Bash - How do I loop through subdirectories and extract the files

I have a directory called 10K_TIF (main directory). Within this main directory are multiple sub-directories each containing tif images. I want to read each TIF image and extract its path using a bash ...
2
votes
2answers
73 views

redirect output of tee and grep for multiple logfiles

Redirecting output from a script STDOUT + STDERR toLogfile 1 and a grep to Logfile 2 ./run_test.sh 2>&1 | tee -a /var/log/log1.log | (grep 'START|END') > /var/log/myscripts.log How can I ...
2
votes
1answer
73 views

While loop checking JBoss status down or not, giving error

The intention of the following code is to check status of JBoss, the while loop iterates until the JBoss status comes to the 'DOWN' state. ` I have the following script, which I've set to this ...
4
votes
3answers
86 views

How to convert an unsigned decimal (less than 1<<32) to 4 bytes (binary) in bash?

Example: $ decimal=$(( RANDOM << 17 | RANDOM << 2 | RANDOM >> 13 )) $ echo $decimal $ printf "%08x" $decimal | xxd -r -p >bytes The result is in bytes file. Can it be done in ...
3
votes
2answers
38 views

How is it possible to execute a command with an unknown number of arguments in a POSIX shell?

I want to search for multiple words inside the current directory. To accomplish this I use something like this. grep -e "word1" -e "word2" -R . This works fine. Taking this one step further, I ...
1
vote
3answers
60 views

Modify some files to add the file name

I have a bunch of text (hundreds of txt) inside a directory. Each of them has a unique filename. I want to insert filename of each file into the first line of respective files. How can I do that using ...
3
votes
2answers
118 views

Extract text including parens

I have some text like this: Sentence #1 (n tokens): Blah Blah Blah [... ... ...] ( #start first set here ... (other possible parens and text here) ) #end first set here (...) (...) Sentence #2 ...
0
votes
3answers
85 views

Bash Combine Replacement and Sub String Extraction in One Step

For a string in this format: ./my-site.sub.domain.com I would like to remove the .,-, and /, and trim the remainder to 16 characters: mysitesubdomainc I've done this ...
2
votes
0answers
1k views

How to test shellshock against remote machine using a simple script [closed]

I am interested in testing for shellshock vulnerable machines that I don't have shell access to on my LAN's and WAN's such as IPMI cards and Internet of things devices. What is the best way to ...