Questions tagged [shell]

30447 questions
0

votes
0

answer
2

Views

Can I get three-way *word* diffs using e.g. dwdiff with diff3?

I know there are GUI's that show word-diffs in three-way diffs, but is there a command-line way I can show three-way diffs with word-higlighting the same way that I can get two-way diffs word-higlighted with diff -u a b | dwdiff -u ?
unhammer
1

votes
3

answer
316

Views

How to print first word of first line and last word of last line in unix in a file

Suppose there is a file file1.c It has 100 lines . I need to print first word and last word of that file.
user265906
1

votes
2

answer
5k

Views

How to download Dash video files as they appear on the server?

Is it possible, given an mpd file like https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd, to easily download all the Dash files stored on the server (assuming we know that it's static content on the server). That is, I should be able to run an HTTP server serving the content I downloaded, an...
Peter Tseng
1

votes
1

answer
1k

Views

SFTP bash shell script to copy the file from source to destination

I have created one script to copy the local files to the remote folder, the script is working fine outside of if condition but when I enclosed inside the if condition the put command is not working and logged into the remote server using sftp protocol and when exist it's showing the error: put comm...
Ashish Sood
0

votes
0

answer
16

Views

Lookahead works with other languages but not in Shell

I have a string on $OUTPUT variable and I wanna get the only the backup directory. I've tested my regex on regex101 and with other languages, and it works, but in Shell, it doesn't. OUTPUT='Backup created at /data/bkp/bkp-2019_04_25/dremio_backup_2019-04-25_15.56, tables 25, uploaded files 0' REGEX=...
Allan Sene
0

votes
2

answer
14

Views

Correct Regex in SFTP bash script

I want to automate a SFTP process to transfer the last file created in local server and send it to remote server. In local server I have '/Source/Path/' I have files named like below: Logfile_2019-04-24 Logfile_2019-04-24_old.txt This is my current script: dyear=`date +'%Y' -d '1 day ago'` dmonth=`d...
Ger Cas
0

votes
0

answer
10

Views

bash - file name in the content

would you be able to help me a bit. I try to write a short script which will find in the current directory all files that contain their name in their content. I was trying with the below but still can't find good solution to the problem: #!/bin/bash for i in *; do if [ -f '$i' ]; then z=`cat $i | gr...
axel_87
2

votes
3

answer
76

Views

Set file modification time from the date string present in the filename

I'm restoring a number of archives with dates within their names, something along the lines of: user-2018.12.20.tar.xz user-2019.01.10.tar.xz user-2019.02.25.tar.xz user-2019.04.19.tar.xz ... I want to set each file's modification date to match the date in their filename by piping the filenames to t...
tobiasfried
1

votes
1

answer
25

Views

Bash grep output in addition to echo within if statement

I have a simple script that checks if images are being used within our html directory. I have a file called imageserver.txt which looks like: imageserver/icons/socialmedia/sqcolor_tumblr.png imageserver/icons/socialmedia/sqcolor_gaf.png imageserver/icons/socialmedia/sqcolor_yelp.png imageserver/ico...
Zak
1

votes
1

answer
41

Views

Download artifacts from Maven repository without using Maven

In various shell scripts, we need to download artifacts from a Maven repository (Nexus 2.x at the moment, but may change in the future). The servers that run the scripts usually have no Maven installed. So I am looking for something http based. On the one hand, there is a REST interface which can be...
JF Meier
1

votes
1

answer
58

Views

Yq: retrieve object keys names

I have a YAML file (docker-compose file in my case) that looks like this: networks: foo: some_opts: 'covfefe' bar: some_opts: 'such wow' services: apache: image: 'apache:1.0.0' restart: always mysql: image: 'mysql:1.0.0' restart: always php: image: 'php' restart: always I would like to extract the s...
PierreF
1

votes
2

answer
35

Views

How does the builtin shell command “type” know the path of given commands?

How does the built-in shell command type know the path of a given command. Does the shell have a table for most used commands that includes the paths of those commands, or does the shell search those commands in the system?
Alp Başar
1

votes
3

answer
52

Views

Why is “ls -1 $fl | wc -l” not returning value 0 in my for loop?

I am trying to add a condition in a for loop to check the existence of a file as well as check for file size > 0 KB. Period file contains monthly data: 20180101 20180201 20180301 20180401 20180501 There are individual files created for each month. Suppose a file is not created for one month, (201802...
user8611207
1

votes
3

answer
57

Views

grep for a variable that contains “+”

Trying to pickup the second row using grep and it dosent work if it has a '+' character i have tried with fgrep & instead of -P tried with Fx or x and -w but none of them worked. File prereq.txt contains this : WS+1 whatever 2222 WS--1...
Yashas K.M
1

votes
1

answer
49

Views

How to empty an array in bash script

I am trying to get specific information from a bunch of files. Iterating over a list of files,greping for what I need. I know for sure that each grep will give more than 1 result and I want to store that result in an array. After finishing the work specific to file, I want to erase everything from a...
gkr2d2
1

votes
2

answer
30

Views

Meaning of “! -S” in shell script

I am new to shell scripting, and I have encountered a script I didn't understand: DOWN=true while $DOWN; do sleep 0.1 DOWN=false for i in {1..7} do if [ ! -S 'qdata/c$i/tm.ipc' ]; then DOWN=true fi done done Specifically, what does this command mean: ! -S 'qdata/c$i/tm.ipc'
MS B
0

votes
0

answer
5

Views

Why do I get this message: “bash: export: `:./': not a valid identifier” when I open the terminal?

Yesterday this message: bash: export: `:./': not a valid identifier started showing up in my terminal. As well as the color from my name has disappeared. Anybody know how to fix it?
hackerNuB
0

votes
0

answer
7

Views

How would I get and filter info that's printed in the terminal

If the terminal printed(echoed) a bunch of strings like: aPath aSecondPath aThirdPath How would I filter through these and find the ThirdPath for example?
Gekyu
1

votes
1

answer
1.6k

Views

Meaning of '@' in “@set -e” command in Makefiles [duplicate]

This question already has an answer here: What does @: (at symbol colon) mean in a Makefile? 2 answers In Makefile, in commands of the form all: @set -e; \ do more stuff I know the set -e commands the shell to to exit on failure. What is the significance of the @ attached to set?
Lavya
0

votes
0

answer
19

Views

golang + Command failing when shell command works

Why does this fail (error 128, not a valid repository): func main() { command_base := '/usr/local/bin/git-upload-pack' command_args := []string{'/repos/bar/foo.git'} cmd := exec.Command(command_base, command_args...) out, err := cmd.CombinedOutput() if err != nil { log.Fatalf('cmd.Run() failed with...
bitcycle
0

votes
0

answer
6

Views

Insert bytes into file using shell

I would like to use a linux shell (bash, zsh, etc.) to insert a set of known bytes into a file at a certain position. Similar questions have been asked, but they modify in-place the bytes of a file. These questions don't address inserting new bytes at particular positions. For example, if my file ha...
fuzzybear3965
1

votes
2

answer
699

Views

How to run multiple brew commands with one line?

I often run the following commands, one after another. I wonder if it can be done with one line? brew update brew upgrade brew cleanup
Stickers
1

votes
1

answer
264

Views

gimp: resize and “unsharp mask” via script

I need to do the same operations for more than 60 files: scale image unsharpen mask Is it possible to execute this from a script possibly passing the scale value ? I'm on Ubuntu if this could influence the answer. edit: What I need to do is to resize some Android icons from 64x64 to 96x96 (as far, m...
marco
1

votes
1

answer
81

Views

STDOUT output getting written to custom file descriptor

I have a function that opens a file descriptor to fd 3 which redirects to a file. The issue I have is that STDOUT from other functions is getting written to the file that fd3 is writing to. So the code is something like below. I don't understand how opening file descriptor 3 at start_report functio...
todd1215
0

votes
0

answer
4

Views

how to set default item of contextmenu whithout 'open' in a special folder

I want to change default contextmenu in a special folder when right click on any files.I appended some contextmenu item on a special folder,such as 'sync to local',I need invoke my application when user double click any files in a special folder, but I can't find the way to set 'sync to local' be de...
MatriQ
1

votes
1

answer
1.7k

Views

How to print a special unicode character in a zsh script

I am trying to print a special unicode character when two files are not different. My code below produces an error saying that '-e: command not found' if [ -n '`diff file1 file2`' ] then `echo -e '\u2713'` fi Edit: I am using ZSH
wginsberg
0

votes
0

answer
5

Views

How to export a confluence page as PDF in Jenkins job?

I'm wrinting a Jenkins job iwth the the help of shell script to export a page in Confluence as PDF and store it as output after the build. How can I achieve that ?
0

votes
0

answer
6

Views

Sum of 2nd and 3rd column for same value in 1st column

I want to sum the value in column 2nd and 3rd column for same value in 1st column 1555971000 6 1 1555971000 0 2 1555971300 2 0 1555971300 3 0 Output would be like 1555971000 6 3 1555971300 5 0 I have tried below command awk -F' ' '{b[$2]+=$1} END { for (i in b) { print b[i],i } } ' but this seem...
Prince Garg
0

votes
2

answer
15

Views

Case insensitive search between two strings in file

I have a file constructed the following way: # comment with keyword One some code here and some more code # another comment with keyword Two some code # more comments and keyword Three lots of code I'm trying to extract the comments and corresponding code lines given a keyword, in a case-insensitive...
marshmcintire
1

votes
2

answer
4.1k

Views

Dockerfile: how to set env variable from file contents

I want to set an environment variable in my Dockerfile. I've got a .env file that looks like this: FOO=bar. Inside my Dockerfile, I've got a command that parses the contents of that file and assigns it to FOO. RUN 'export FOO=$(echo '$(cut -d'=' -f2
Ben Downey
1

votes
2

answer
60

Views

Most Efficient way to find pairs between 2 arrays in bash

I have 2 large arrays with hash values stored in them. I'm trying to find the best way to verify all of the hash values in array_a are also found in array_b. The best I've got so far is Import the Hash files into an array Sort each array For loop through array_a Inside of array_a's for loop, do anot...
Don Richards
1

votes
1

answer
58

Views

Make a string both valid JSON and shell escaped

I have an array which I want to convert to a JSON string. One of the elements has a backtick. This would cause an error when I try to run the command in the shell: data = [['305', 'John Smith', 'Amy Smith`', '10/11/2008', 'Medical', {'page_count'=>4}]] json_str = data.to_json.gsub(''','\'') cmd = 'n...
Donato
1

votes
2

answer
195

Views

Use JQ “contains” and suppress errors when key not found

I am trying to get the value based on the 'contains' value of another key in the same object I have already tried a code and it works and outputs the result that I want, but some objects in the JSON do not have this key as such I get: jq: error (at :1): null (null) and string ('BBC') cannot have the...
mfaiz
1

votes
5

answer
45

Views

How to add “/1/” as a line number in a txt file?

In Unix I want to add slash before and after the line number in a .txt file this command only shows the line numbers cat -n txt.file this: Tony Alpha Bravo to this: /1/ Tony /2/ Alpha /3/ Bravo
user10813205
1

votes
4

answer
60

Views

bash get only the highest (folder hierarchy wise) location result into a variable

I am trying to get only the highest (folder hierarchy wise) location result into a variable using bash. [email protected]:/tmp/test/frontend-2.0$ find -name pom.xml ./server/pom.xml ./server/mock/pom.xml ./assembly/pom.xml ./pom.xml I want only the location of the parent folder of the pom.xm...
1

votes
1

answer
63

Views

Why do quotes in shell scripts behave differently from quotes in shell commands?

I'm using WSL (Ubuntu 18.04) on Windows 10 and bash. I have a file filename.gpg with the content: export SOME_ENV_VAR='123' Now I run the following commands: $ $(gpg -d filename.gpg) $ echo $SOME_ENV_VAR '123'
Leo Jiang
1

votes
3

answer
59

Views

Check if a string does not exist in multiple arrays

Trying to check and see if a string value is NOT a member of two different arrays. If the string value does not exists in any of them, then i need to perform a statement. I was able to do it with an if statement.... if [[ $REQ_FIELDS_LIST != *'$XFR_FIELD'* && $NON_INPUT_FIELDS_LIST != *'$XFR_FIELD'*...
Brian Gurka
1

votes
2

answer
79

Views

What's the equivalent to ${var:-defaultvalue} in fish?

Hello I am trying to translate my .bashrc to fish format almost done, mostly is clear on the documentation but this part is giving me a headache.. is so my gnupg works with my yubikey ssh etc etc.. The fish version is latest 3.0 under Arch GNU/Linux original on BASH: # Set SSH to use gpg-agent unset...
cfernandezlinux
1

votes
2

answer
70

Views

need help on shell script for expected output

I have an input file called input.txt like this: powerOf|creating new file|failure creatEd|new file creating|failure powerAp|powerof server|failureof file I extract the text up to just before the fist capital letter in the first field and store those snippets in output.txt: power creat I used the...
Mohan
1

votes
2

answer
75

Views

execvp() return value if path is wrong

I am currently writing a custom shell script in C. In order to execute the command, I use the execvp() function. For example: if((execvp(args[0], args)) == -1) //args is a char **array containing the commands arguments { printf('ERROR: Wrong command\n'); exit(EXIT_FAILURE); } The thing is, when 2 co...
Thanos Manolis

View additional questions