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

learn more… | top users | synonyms (2)

1
vote
2answers
49 views

how to get string between braces along with string without braces using awk

My input is: ABC_DFG_FRE s(DFR_GHY_JUY) BGR_KIU_PLO s(VFR_KJU_MKJ) output sholud be: ABC_DFG_FRE DFR_GHY_JUY BGR_KIU_PLO VFR_KJU_MKJ
1
vote
1answer
40 views

Create a log file with the same name as input file

I'm new to linux shell scripting. I have few input files that I have to parse one by one. So in my "work in progress" WIP folder I have one input file at a time. While one file is under processing I ...
4
votes
1answer
125 views

how to set environment variables from a shell script? [duplicate]

I'm trying to set environment variable through a shell script. Here is the script with various techniques: #!/bin/sh echo "export SOMEPATH=/root/some" >> /root/.bash_profile echo "export ...
1
vote
1answer
61 views

Fastest way of find and replace in large file with replacing filed present in another file

I have two files. File1 is a csv with 60 fields: 111,Check1|^/h1/h2/h3,22062014184500,20,0..... 111,Check2|^/h43/h40/h9,22062014184500,4,..... 111,Check3|^/h1/h3/h4,22062014184500,0,0,..... File2 ...
0
votes
1answer
53 views

Disable Touchpad automatically at startup

I'm running Mint 17 Mate on a new HP250 laptop. I can turn off the touchpad by typing the following from terminal: synclient TouchpadOff=1 Now I want to disable the touchpad automatically each time ...
2
votes
1answer
24 views

move the search content to different directory

I am on Oracle Solaris. I am using: grep "searchstring" filename.* above command returns my search result. Now I want to move the all the files in above search result (all the files not the ...
2
votes
1answer
68 views

Integer part from float operations without | bc

I read a billion of discussion about this but still have confused thoughts. I just need to use bash to calculate some parameters, and for this operation I need to get the integer part of a float ...
1
vote
1answer
23 views

How do I obtain the kill signal / message / reason within a script?

I am using the following trap: trap OnExit EXIT And in my OnExit function I would like to capture all the info I can on what happened so I can write it to a log file. Id like to know who, why, how, ...
2
votes
1answer
49 views

Why is the PGID of my child processes not the PID of the parent?

So I keep reading everywhere that this command should terminate all child processes of the parent process: kill -- -$$ Using a negative ID with the kill command references a PGID and from the ...
2
votes
3answers
55 views

Concatenate filename inside of CSV file for each line for multiple CSV files

I have lots of CSV files and I need the filename of each specific CSV file in every line of each file. Original file content of abc123.csv: ColVal_1;ColVal_2;ColVal_3 ColVal_4;ColVal_5;ColVal_6 ...
1
vote
7answers
84 views

Get text between two special characters in a line using shell

I have a line which comes from a file via: cat aaa.txt | grep "HIJK" Output gives: HIJK="My name is HIJK" I need to get the text My name is HIJK into a variable in a shell script. I have tried ...
0
votes
1answer
38 views

How to make xargs ping and head output as expected?

Given an array of domains I would like to obtain their IP addresses, in the following format: 98.139.183.24 98.137.236.24 This script #!/bin/bash domains=(yahoo.com yahoo.ca) printf "%s\0" ...
3
votes
6answers
68 views

Collapse some repeated parts of successive lines

I have data in notepad like this: 4480-1 4480-2 4480-3 4480-15 4581-1 4581-2 4581-3 4581-4 Can we do it using for loop sort of things? With sed? My required output is ...
0
votes
2answers
32 views

list files and store it in variables

im new with shell programming. my goal is to give the user a selection which file should be run. i catch all available scripts in one var with: var=$(find script*) so far so good.. this is the ...
0
votes
0answers
57 views

Find if the file is compressed or not

I need to find whether the file is compressed or not in script.If it is compressed I need to uncompress and send as attachement. My find command results in two files sum12.pdf.Z and sum23.pdf.Z My ...
0
votes
2answers
35 views

names that occur the largest number of times in a data set

users directory ---------------------- hjsyeh hellodir ; awgshd newdir; hjsyeh hidir; jkdhjk welcomedir the above given are set of users and the directories they created .How can I ...
0
votes
2answers
36 views

Output multiple strings out of multiple files

Hi my current code is: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gBatch_*"\ -daystart -mtime -1 -exec grep -rl "ERROR" "{}" + | xargs -l basename if [ $? -eq 0 ]; then ...
1
vote
2answers
51 views

Hiding Script Command Output

I'm building a shell script to automatically configure a specific computer with the best settings. I would like to hide all output from this script except for echo output. Is it possible?
2
votes
2answers
177 views

How to parse multiple string patterns in linux shell script

I am new to linux shell and I had a hard time thinking of the solution to this. Can somebody help how to parse multiple strings (data) in a file? For below file, I want to parse all the values next to ...
6
votes
3answers
69 views

Print a multiline variable in a column

I have a script that collects values from a cluster. The values, in some cases, have multiple lines. I have a printf format that specifies how the data should be positioned however, it doesn't take ...
2
votes
1answer
519 views

What is wrong with this code?

I have a script that goes like this: while : do Start_Time=$(date +"%s") MAIN PROGRAM GOES HERE (CROPPED TO SHORTEN THINGS) Run_Time=$(( $(date +"%s") - $Start_Time )) if [[ ...
1
vote
1answer
25 views

Submitting jobs with sequential completion

If I have numerous jobs that rely on environment variables, how can I submit them sequentially? Here is my attempt that has not been working, week 6 is always submitted (and finishes) before week 5. ...
1
vote
2answers
37 views

Problems with basename in a loop

I am new at shell script programming and I'm trying to execute a software that reads a text and perform it's POS tagging. It requires an input and an output, as can be seen in the execute example: $ ...
2
votes
4answers
240 views

Inserting a line in a file only if this line isn't yet part the file

Total newbie to shell scripting, I am searching to create a script to automatically apply some custom configuration to text based configuration files. In the present case, I am searching to add 2 ...
0
votes
2answers
81 views

Exit the bash function, not the terminal

I have a bash script as below which installs zookeeper but only if not installed already. ##zookeper installZook(){ ZOOK_VERSION="3.4.5" ZOOK_TOOL="zookeeper-${ZOOK_VERSION}" ...
2
votes
3answers
51 views

How to set variables from find+exec?

I am trying to write a bash script where I am trying to find if some location has empty files or not and send an email if found. I first thought about combining "find" and "mail" together, but if the ...
1
vote
1answer
28 views

Identify python script is waiting for a manual input

I'm writing a shell script which executes a Python script. The Python script halts for a manual enter to be provided. However, I don't wan't to have to press enter each time to the script. Instead, I ...
11
votes
7answers
602 views

Shortest way to extract last 3 characters of base (minus suffix) filename

I'm trying to set a variable in an sh script to the last 3 characters of the base name of a file (by base name I mean without the path and without the suffix). I've succeeded in doing this but, purely ...
0
votes
2answers
50 views

UNIX: Submit job only after previous job completes?

I would like to submit the same .sas job iterating over an argument, but I would like job only to be submitted after the previous is completed. Here is my attempt: #!/bin/ksh export weeks="1 ...
4
votes
4answers
184 views

Single instance of script, but only with same arguments

I have this beautiful little code here that will exit from a script if there's another instance of it running: single_instance(){ if pidof -x "${0##*/}" -o %PPID >/dev/null; then exit ...
0
votes
1answer
55 views

How to exit the script in ssh session?

My script contains a ssh command to login to remote server and execute a few commands, The command checks if a file exist and if not it should come out of the entire script. ssh $user@$hostname "if[ ...
6
votes
2answers
336 views

Do parentheses really put the command in a subshell?

From what I've read, putting a command in parentheses should run it in a subshell, similar to running a script. If this is true, how does it see the variable x if x isn't exported? x=1 Running ...
0
votes
2answers
43 views

Passing a variable to a bash script that uses 'EOF' and considers the variable a literal [closed]

in this script i end up with "$1" being saved to the /test file. #!/bin/bash cat > /test << 'EOF' $1 EOF the truth is.. i need to keep 'EOF' as 'EOF' because my argument($1) contains ...
4
votes
6answers
882 views

How to tell “cat” command to not hang on when there is no path provided?

I am simply trying to get a bash script to return the content of a text file. #!/bin/bash cat $1 the problem is.. when the path to a file is not fed to this bash script... how will it even close ...
0
votes
1answer
30 views

script to zip a file and change its owenrship

I have a script I am working on that reads off of a text file and will use the information stored in the text file to put each line entered in as an array. This array is a reference to files that are ...
1
vote
1answer
78 views

Attachment missing in Unix mail when multiple files were attached

I am trying to attach multiple files in Unix, which are the result of a find command. When I try to send the mail, the attachments are missing. dir=$path echo "Entered into $spr/sum_master" for fil ...
-1
votes
3answers
72 views

Checking if line in file exist

I have a bash script which asks a user for the number of CPU cores and saves it to variable named $cores. Now I want to add this variable to .bashrc, so I ask user how much CPU cores he has and then ...
2
votes
1answer
53 views

shell script for mounting external device to mount point

I want to make a script to mount an external device to a particular mount point e.g say /mnt. Let me elaborate my question, suppose I run fdisk -l in terminal I would get this output Disk identifier: ...
-2
votes
1answer
32 views

Read file and do below command [closed]

From the 2 different web page the output goes to a single file called "traffic" From one page it always has a string "sqr" and from the other page it does not have the sqr string but "attach" I need ...
0
votes
4answers
77 views

Error: integer expression expected

I have written a script to determine the Load average on the server as follows: #!/bin/bash loadavg=`top -b -n1 | grep -i load | awk -F, '{print$4}'| awk -F: '{print $2}'` if [ "${loadavg}" -le 1 ...
0
votes
1answer
91 views

How to display a .jpg file using fbi in a bash script for set amount of time and then execute the next command in the script

I am trying to use fbi in a bash script to display a series of .jpg images. But once fbi begins its process, it continues to cycle through the images and I only want to display each image once for a ...
2
votes
3answers
76 views

Strange formatting of date in bash script

I am working on a script to sort my downloads folder by the date the files were created. This is the script I am using: #!/bin/bash cd ~/Downloads for FILENAME in * do if [[ -f $FILENAME ]]; ...
-1
votes
2answers
43 views

How to get `expr match` to extract colon-delimited key-value pair?

Given: myvar="present-value: 1", I'd expect expr match "$myvar" '\([0-9]\)' to output 1. However, instead it outputs blank and exits with a non-zero status code indicating no match. How can I get it ...
2
votes
1answer
82 views

Attach files for sending mail which are the result set of find command

By using find command I got multiple files. Now I want to add all these files as mail attachment. Please help me how to add these files as attachment in single mail. I want to implement this in ...
2
votes
2answers
55 views

bash function execution from command line

I love to play with bash script a lot. But I want to enhance the way I use bash script. I have a script(nepleaks.sh) as below used during my programming, ~ 1 clean(){ ...
0
votes
2answers
102 views

How to get the value from rows and columns from text file in bash?

I am working on a bash project. I need to get all the values (one at a time because I will be using them somewhere else) from a text file. The text file I will be getting is structured like this: ...
4
votes
2answers
67 views

Launching a terminal emulator without knowing which ones are installed

I need to write a script that will launch a terminal emulator and run a particular command in it. Since I don't know which terminal emulators have been installed on the target system, how could I find ...
0
votes
5answers
102 views

how to extract part of a filename before '.' or before extension

I have files in format below: abc_asdfjhdsf_dfksfj_12345678.csv hjjhk_hkjh_asd_asd_sd_98765498.csv hgh_nn_25342134.exe I want to get the value before the . and after the last _. The result would ...
3
votes
4answers
155 views

How to cut everthing until a specific word / after a find in a script

Hello I try to get the output of files from today wich contains ERROR. I use this to find the files I want: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gandalf_*"\ -daystart -mtime ...
2
votes
3answers
68 views

Use awk results as parameters to another command

I'm extracting rows from a set of text files with awk. The files look like this: 1000 1 75 1000 2 76 1001 1 76 1001 2 80 I'm searching several directories of these with this ...