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

learn more… | top users | synonyms (2)

0
votes
2answers
23 views

command to put hyphen in the second column if the space is given between a word [closed]

Suppose you have a file called test.txt with data like: you wel come how nice what do ing How can I add a hyphen in the second column if the space is given between a word?
2
votes
1answer
63 views

Tracking where the script stopped after timeout

I've got a shell script doing connection performance test, that I timeout if it takes too long. Upon timeout, it logs the results of a few commands so I can make myself an idea of the system status ...
1
vote
2answers
362 views

What is the meaning of a trailing “:” (colon) in *nix? [closed]

I am currently following a tutorial about shell scripting located here: http://www.cs.columbia.edu/~sauce/tutorial/ashell.html and I believe my script matches that one exactly. However, when I try to ...
0
votes
1answer
37 views

Identifying duplicate fields and REMOVE both with awk

Previously, I asked the question: Identifying duplicate fields and print both with awk. I have a file with multiple columns and wanted to identify lines where specific column values (cols 3-6) had ...
1
vote
2answers
48 views

How to execute a command randomly over a given time interval?

I am interested in a running a Unix command once randomly over a given time interval. For example, if the command is ls and my time interval is between noon and 2pm, how could I start a background ...
3
votes
2answers
33 views

Why builtin times doesn't work in pipeline?

I've the following sample script: #!/usr/bin/env bash sleep 5 printf "times cmd: " times printf "pipeline: " times | ( read user sys; echo $user; ) printf "head: " times | head -n1 printf "times cmd ...
1
vote
1answer
21 views

Pause (with read or similar) in xargs

I have a script that looks something like the following. find /path -type f | sed -re 'stuff' | xargs -Ix sh -c '{ echo "information about x" ./exe < x read }' My goal is to provide each ...
-3
votes
7answers
111 views

Is there a way to prevent sed from interpreting the replacement string? [closed]

If you want to replace a keyword with a string using sed, sed tries hard to interpret your replacement string. If the replacement string happens to have characters that sed considers special, like a ...
5
votes
6answers
178 views

Take grep value and output the count and the value together

I am trying to make a bash script that greps value and output the count and the value together Something like this grep -c 'Thenis' example.txt > example.lst But in that list file not only to ...
0
votes
2answers
41 views

Sort words in file

i've got some problems i'm not capable to overcome. I need to count the first let's say N words in a txt file. Then , i have to print them in decresing order, followed by the number of occurences.The ...
0
votes
0answers
33 views

Updating/compile sendmail script not working.

I have wrote a script to update sendmail and compile on unix system I put those lines if [ ! -e $CWD/src/$NAME-$VERSION.tar.gz.sig ] then echo "$NAME-$VERSION signatures missing" wget -c ...
1
vote
0answers
19 views

How to count nodes and get attribute value without using xpath

Currently I have a shell script like this: LOGIN=`curl 'https://www.ponta.jp/u/LWAS900/SLWAS900010.htm' -sS | grep '<input type="hidden" name\|<form\|</form'` for i in $(seq $(printf ...
3
votes
1answer
83 views

List of VBox Machines Help?

So, I'm writing up a bash script to list out the VM's on my host, so I can make sure they are fired up when the host machine restarts... no problem here... my issue is getting the list of the ...
1
vote
0answers
46 views

Error “dircolors: no SHELL environment variable, and no shell type option given”

Running Linux Mint 17.3 Cinnamon A while ago a created a script that changed the colors in the Terminal (to match a tutorial I was following) However if I open the terminal on another account, I get ...
1
vote
1answer
47 views

Exporting Variables and setting Global Variables in Bash [closed]

My objective is to create a list of variables that can be called or referenced by any test script that is being executed. There are a lot of test scripts on the system but the variables are ...
2
votes
3answers
49 views

How to wait for all spawned and backgrounded processes to finish in bash script

I've looked and looked and can't find a working solution to a bash script I'm trying to create to shut a process down and wait for it and spawned processes to finish. I'm still learning a lot of ...
1
vote
2answers
25 views

how to split long psql command in bash script over several lines

I have a long psql command to execute within a bash shell script, and I am wondering what the correct way is to split it across several lines? The standard Unix script 'split line' backslash ...
0
votes
1answer
22 views

i want to remove tag in xml when it is repeating multiple times

I want to comment particular tag with particular value from xml when it is repeating multiple times example: <t1> <t2>hi<t2/> <t1/> <t1> <t2>hello<t2/> ...
1
vote
0answers
15 views

Schedule (Cron) executing tasks based on bash scripts using CronniX

I'm still quite new you Mac and OS X but do have some background about other UNIX based systems, so please excuse for any misunderstandings. My goal is to implement a function that executes certain ...
2
votes
1answer
46 views

How do I turn entire stdin into a command line argument verbatim?

Attempt 1 xargs -I '{}' -0 -n 1 myprogram --arg '{}' --other-options But that does not preserve zero bytes. Also the program may run multiple times. But instead of failing in case of zero byte ...
1
vote
1answer
42 views

How to prevent bash from transforming arguments?

I am trying to use an argument of the script to find other files. The problem is that when i give the script the argument x.* in the command line, it is transformed into x.sh. Any ideas how i can get ...
1
vote
1answer
36 views

Running chown in bash script produces errors

I'm working on a script that downloads a file with bar:bar ownership, then changes the ownership to foo:server. So I wrote a side script(chown_test.sh) to implement the changing of the ownership via ...
1
vote
3answers
58 views

grep a awk string from a file and write to the other part of string file

My file, aaa,has 5 lines. 01_AAA-11-ID22 02_BBB-33-ID44 03_CCC-55-ID66 . . I tried to grep anything after underline from a file bigfile.txt for i in $(cat aaa) do A= $(awk -F '_' '{print $1}' $i) ...
1
vote
1answer
23 views

Long running script stops sending output to file

I have a script that I'm using to capture some status of the server at 10 second intervals. The script is as follows: for (( ; ; )) do /usr/local/apache/bin/apachectl fullstatus sleep 10 ...
1
vote
1answer
56 views

split file into multiple pieces

Problem: given a file samplein, it can be split up into multiple pieces as follows: $ cat samplein START Unix Linux START Solaris Aix SCO $ awk '/START/{x="F"++i;}{print > x}' samplein $ ls F* ...
4
votes
2answers
275 views

How to wait for the copying process (cp) to finish?

I want my RPi 2 (with MiniBian (a minimal version of Debian-based Raspbian OS) as its OS) to execute a script when it detects a USB flash memory is inserted. So this is what I have done: I created ...
0
votes
1answer
34 views

extract text from txt a file [duplicate]

I have a a file containing about 20 million sentences, how can I extract 2 million sentences out from it? I thought about using the split command like this "split -l 2000000 sub2016", but then it ...
0
votes
1answer
15 views

Getting error while using httpd -v command in script

I wrote a script to check the details of Web server's(RHEL) and save the output into a file. But the script is not passing the command httpd -v in the loop. Here is the script. #!/bin/bash for i in ...
0
votes
0answers
27 views

Process multiple csv Files in to one file with Format Arcsight would parse easily

I need some help in writing a script to process multiple csv files to a single csv file which is formated to be parsed by arcsight Here is the script so far, it is processing the first Two file ...
0
votes
1answer
39 views

How to replace single quotes and &apos in a file

I am trying to replace single quotes in a file and I used the command as sed /s/'//g filename and this command works fine but I have &apos character also in my file and which is not getting ...
1
vote
1answer
49 views

How to allow a bash shell script to loop for 3 retries before exiting (prompt for username/password)

I have a shell script that will ask for username and it will check against a list. if the name is inside the list, it will run another shell script but if the name cannot be found, it will prompt a ...
0
votes
1answer
29 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
20 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
277 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
62 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
40 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
47 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
125 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
61 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
147 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
424 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
24 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
108 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 = ...