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

learn more… | top users | synonyms (2)

0
votes
1answer
28 views

Format the output of awk command

I have to format the output of the awk command which gets the input from a file Sample Input File 123 ABC 12 23 34 45 56 67 78 13 234 DEF 23 34 45 56 67 78 89 345 GHI 34 45 56 67 78 90 10 01 99 456 ...
-1
votes
1answer
26 views

cut command behaving differently when its output is “ * ” [duplicate]

I am trying to create a shell script, below is a part of which where i am trying to extract some value from a record in a file: tgt_val=`cat $file_name | grep "$string_name" | cut -d"|" -f$column_no` ...
0
votes
0answers
19 views

Pantheon-Terminal open multiple tabs script

I'm new to linux so bear with me. I'm looking for a script that will open pantheon-terminal with 3 tabs, each with a certain location / commands. I have a basic script that when I run from the ...
1
vote
2answers
60 views

Extract Values from Formatted Text

Is there an easy way to extract variables from a text file? E.g. given the output from ab: This is ApacheBench, Version 2.3 <$Revision: 1638069 $> Copyright 1996 Adam Twiss, Zeus Technology ...
6
votes
1answer
276 views

Use md5sum to verify file in a script

This question is probably quite easy but I don't know how to accomplish this. I want to verify a file using md5sum -c file.md5. I can do that by hand, but I don't know how to check the validity in a ...
2
votes
1answer
21 views

Find all git repos that do not contain any one of .gitignore and .gitattributes

I basically want to find all git repos that have neither a .gitattributes nor a .gitignore file at the root. I used find . -type d '!' -exec test -e "{}/.gitignore" ';' -print to find it but it lists ...
1
vote
3answers
61 views

dynamic case statement creation

I have a rather long case statement (about 150 patterns to match). case "$line" in pattern1) ret=result1;; pattern2) ret=result2;; pattern3) ret=result3;; ... ... esac However, this is ...
1
vote
2answers
37 views

How can I run this python script on all html files under a directory? [duplicate]

I have a python script $ cat ~/script.py import sys from lxml import etree from lxml.html import parse doc = parse(sys.argv[1]) title = doc.find('//title') title.text = span2.text.strip() print ...
-1
votes
0answers
12 views

List all files in USB device from /Volumes shell script [duplicate]

To clear things up I have setup folder actions on my mac for whenever a USB device is plugged into my mac it will run a shell script. When I list all files in the Directory /Volumes i get $ ls -a . ...
1
vote
0answers
26 views

Netcat server/client for a social thread

I have been learning nc for a while now, and I decided to make a social thread server for it in bash. Surprisingly, I got it working, but I have a couple problems with it. My main problem I want to ...
0
votes
2answers
41 views

perl: Replace string in file with double quotes

Following up question from http://unix.stackexchange.com/a/254637/18887 I have the following string in a bash variable This rule forbids throwing string literals or interpolations. While JavaScript ...
3
votes
3answers
122 views

Intersperse lines from two files

I have a data file ($file1) which contains two lines of data per individual. I need to intersperse a third line of data from another data file ($file2). So my input looks like: >cat $file1 bob ...
0
votes
1answer
59 views

Using sed instead of grep to output only matching part of line

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in ...
3
votes
3answers
144 views

How do I remove newline character at the end of file?

Let me clear about newline character: $ echo Hello > file1 ; cat file1 Hello $ echo -n Hello > file2 ; cat file2 Hello$ Here you can see that file1 has newline character at the end whereas ...
0
votes
2answers
41 views

Combining two scripts into one

I have two scripts. Both scripts are on the same server (serverA) The first one (serverA) makes an ssh connection to the other server (serverB), and executes the second script, e.g *script1* ssh ...
8
votes
3answers
420 views

Extract text between three single quotes

I have the following in a file description: ''' This rule forbids throwing string literals or interpolations. While JavaScript (and CoffeeScript by extension) allow any expression to ...
0
votes
2answers
22 views

return value of command not displayed in script

If I execute the below rsync command in command-line , I am getting the proper return status /usr/bin/rsync -azv -p /home/zaman x11server:/home/zamanr &> rsyncjob/output."$datetime" echo $? ...
0
votes
3answers
41 views

How to put variable in for loops? [duplicate]

for seq in {046725..046899} do #body done Above segment of code runs beautifully keeping preceding zeroes in seq variable but why following code segment doesn't run? Is there any way? I need seq ...
-2
votes
2answers
103 views

shell scripting if statement doesn't work [closed]

I wrote that script but if I run it I get this output: ./autotex: line 7: syntax error near unexpected token `then' ./autotex: line 7: ` then' The script is: #!/bin/bash while [ $key = ...
43
votes
4answers
903 views

How does bash differentiate between brace expansion and command grouping?

I've noticed that { can be used in brace expansion: echo {1..8} or in command grouping: {ls;echo hi} How does bash know the difference?
0
votes
2answers
29 views

Bash script doesn't convert variables [duplicate]

I was attempting to create a bash script to run a backup of my Raspberry Pi to my Box account via FTP. Most of it works, but for some reason it won't convert variables to the text they stand for. When ...
1
vote
2answers
37 views

How i check if a specific number.word exist in a line?

like i have this lines on the file {218394 ted 'y' ted} {131241 john 'n' ted} and i want to check if its y continue if its n dont ! i have this code until now!: read -p "Enter your answer : " echo ...
1
vote
1answer
43 views

How to get a deterministic complete dump of all iptables rules?

How to get a deterministic complete dump of all iptables rules? By complete, I mean all tables of iptables. By deterministic, I mean when the command is run multiple times without modifying any ...
3
votes
3answers
42 views

How to treat numbers starting with zeroes as decimal integer

Input would be file name like following : A-B-000001-C A-B-000002-C ..... ..... A-B-999999-C All file should be sequential. I want to find missing sequential file names. For this I'm separating 6 ...
5
votes
2answers
68 views

In bash script, what's the different between declare and a normal variable?

In bash scripting: we create variable just name it: abc=ok or we can use declare declare abc=ok what's the different ? and why bash make so many ways to create variable?
1
vote
1answer
43 views

one-dimensional array in shell not working for indexes greater than 08

I have been wondering why the one-dimensional array in shell isn't working for the sub-script / index 08 and 09. How come this happen? $ cat check month_arr=(0 31 30 31 30 31 30 31 31 30 31 30 31) ...
-1
votes
0answers
23 views

How can i list a specific line/word from my text?(shellscript)

I have this until now: if [[ $1 = "-s" ]] && [[ $2 =~ ^[0-9]+$ ]] echo "ok" for $2 = 1 awk {print $1} something.txt fi what i want is when for example when i enter -s 2 to list the second ...
2
votes
3answers
172 views

Can I put ranges to parameters? [duplicate]

I have this code: if [[ $1 = "-s" ]] && [[ $2 = 0-9 ]] then echo "yes" fi 0-9 does not work for me. What I really want is to type, for example, -x 3 (or any number).
0
votes
2answers
66 views

Making csv file

I have two different textfiles.txt (textfile1.txt and textfile2.txt) with different data sets in them. Is it possible to compile two seperate .txt files as a single CSV file? UPDATE textfile1.txt ...
2
votes
1answer
25 views

Appending to a file suffix range with echo and tee

I am unable to figure out how to properly pipe and tee to append to a range of files. Instead of manually typing them out echo "help!" | tee >> file1 file2 file3 I am trying to figure out: ...
3
votes
1answer
45 views

Colored Output from Bash Script

I'm running grep inside a bash script. If I run the grep command directly, I see colored output of the file name and search string: grep -i username /tmp/sess_* If I put that command in a bash ...
1
vote
5answers
56 views

Filtering out inputs to textfile

I am using and Raspberry Pi (running raspbian) and I have a shellscript continuously outputting values into textfile via this command: wavemon -d |grep -i signal >> textfile.txt The output is ...
0
votes
1answer
62 views

How do I ask password by GUI prompt while using sudo in script?

I use Trisquel GNU/Linux with GNOME Flashback Desktop Environment. I need a GUI password prompt for user for executing command with sudo in script. Example consider following script: zenity ...
0
votes
1answer
66 views

How to prompt a password automatically in Unix Shell script? [duplicate]

I have the below line in a script. When I run it, it prompts for a password to copy files in the server. I need the password to be taken from the script. Please help me resolve this. for i in cat ...
0
votes
1answer
52 views

Unable to kill a process in shell script

I have this script: #!/bin/sh cd ~/.devilspie && devilspie Minimize.ds pkill devilspie exit 0 The first command runs absolutely fine, but in the second line where it needs to kill the ...
0
votes
1answer
19 views

For loop separate $i's [closed]

Hi I want to have "NOTHING HERE" to come out of the for loop but I get NOTHING and HERE pi@ed_pi:~ $ cat test.txt NOTHING HERE pi@ed_pi:~ $ for i in `cat test.txt`; do echo $i; done ...
1
vote
2answers
37 views

Script to Organize Desktop into Folders/Directories by Extension

I'd like to organize desktops by running a script that places all of your files into folders by extension. I found some code through googling and the code I found creates a folder with the name of the ...
0
votes
2answers
35 views

script not reporting service status correctly

I have a script that I use for iperf to be able to start, stop, and check the status of it like a typical service. If I issue a "service iperf start" or a "service iperf stop" it works correctly. When ...
-4
votes
1answer
34 views

find problems again? [closed]

How do i show pipe or socked files from a directory? echo "give name of directory: " read directory if [ -d "$directory" ] then echo "thanks again" else exit fi find $directory -maxdepth 1 -type ...
-1
votes
0answers
15 views

find command problem [duplicate]

I want to show the subdirectories of the given directory that have been accessed by the 'x' last days when x a argument of mine! echo "give name of directory: " read directory if [ -d "$directory" ...
-1
votes
0answers
29 views

find(shell script problem )

I want to show if the files of the given directory changed contents during a specific time period and I want to be able to set that time period as an argument. echo "give name of directory: " read ...
0
votes
3answers
63 views

`Syntax error: “(” unexpected` when creating an array

I have two (Debian) Linux servers. I am creating a shell script. On the first one I create an array thus: #!/bin/bash target_array=( "/home/user/direct/filename -p123 -r" ) That works fine. ...
0
votes
2answers
29 views

Shell script - blanks are not always recognized as such?

I'm confused on how bash interprets blanks while executing a script. In the end, I want a script that is fed by a csv file containing software used by an organisation and it should return the CVEs for ...
0
votes
3answers
21 views

problem with find (shell script)

I want the files of a given directory and use the following script: echo "give name of directory: " read directory if [ -d "$directory" ] then echo "thanks again" else exit fi find /-type f ...
1
vote
2answers
36 views

cd in bash script without alias, function, source [duplicate]

I have a little problem, and hope that anyone can help me. I've written a bash script which should cd me to a directory. My problem is that only the directory in the subshell changes. I've read of ...
0
votes
0answers
26 views

Track command line with timestamps

I want to create a program that audits the command line I/O of a terminal session using its PID. I found out about script command which is pretty much the same to what I want, but the problem is that ...
0
votes
1answer
24 views

Execute a init script from C++ program

I have a script in my /etc/init.d/ which executes an application. I am able to start,stop and get status of the service from terminal. Now I would like to start the same service from my C++ program. ...
3
votes
2answers
74 views

ifdef style conditional inclusions for shell

Consider the following script. #!/bin/sh echo "" | ...
3
votes
1answer
38 views

how to remove 0 (zero) from the day and month but not from the year (01/09/2012) using in Linux (Redhat)

Using Linux (Redhat) I need some help regarding the a/m request When I use dialog: --calendar to output the date. The format will be dd/mm/yyyy but I need the format to be d/m/yyyy for day and month ...
-2
votes
2answers
78 views

How do you remove newline character in the middle of file?

File structure: Col1|Col2|Col3|Col4 123|456|abcdefg Tel.: 689346589934, xyz lckhasfkl|abc I want to remove the newline character from 'col3' only.Please suggest