bash

Bash Script changing the output file for every file

给你一囗甜甜゛ 提交于 2021-02-11 12:39:15
问题 I'm trying to use a command on everyfile .log in a folder but I can't understand how to change the output file for every file in the folder. #!/bin/bash N="0" for i in "*.log" do echo "Processing $f file..." cat $i | grep "test" | awk '/show/ {a = $1} !/show/{print a,$6}' > "log$N.txt" done How can i increment the counter for log$n.txt? 回答1: It's bad practice to write shell loops just to process text (see https://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process

How do I Run Docker cmds Exactly Like in a Dockerfile

試著忘記壹切 提交于 2021-02-11 12:33:31
问题 There seems to be a difference between how Docker runs commands in a Dockerfile versus running commands manually after starting a container. This seems to be due to the kind of shells you can start, a (I assume) non-interactive shell with a Dockerfile vs an interactive one when running something like docker run -it <some-img-id> . How can I debug running commands in a Docker container so that it runs exactly like the commands are run from a Dockerfile? Would just adding /bin/bash --noprofile

Import Error Loading Module using Bash Script on EC2 Instance (AWS)

北战南征 提交于 2021-02-11 12:24:20
问题 I am trying to run a bash script through the user_data argument of the spot_fleet_request method. The script executes all the installations and connects to the filesystem, but when it runs the python file I need to run it gives me the following error: Traceback (most recent call last): File "/home/ec2-user/efs/dir/create_lvl_output.py", line 8, in <module> from modeling import generators ImportError: No module named modeling Where modeling is a folder with a script I am importing "modeling

Why would one run cat|bash before copying/pasting into a terminal?

。_饼干妹妹 提交于 2021-02-11 12:22:28
问题 I've seen someone running cat|bash before pasting commands from the clipboard into a terminal. bash executes commands in bash I do not know why do we need cat here and |(pipe) . What useful effects does this practice have? 回答1: It was my colleague who executed a bunch of command in the terminal, [...] he did cat|bash before pasting those set of commands He likely this to stop Bash from interpreting anything in the commands as editing input, to override any special keybindings and aliases he's

How do I escape a single quote inside single quotes in jenkins-pipeline bash command

北战南征 提交于 2021-02-11 12:13:11
问题 in jenkins-pipeline, I'm trying to use SED to append the following line to the end of a file. sh "sed -i '\$ s/\$/ public_file=\\/var\\/lib\\/jenkins\\/workspace\\/test-project\\ ansible_ssh_common_args='-o StrictHostKeyChecking=no' /' file.txt" but I can't figure out how to escape the below line in my Jenkins file to make it work. ansible_ssh_common_args='-o StrictHostKeyChecking=no' I've already tried the following, which works in katacoda playground, but not in jenkins pipeline. '"'"'-o

Grep for lines not beginning with “//”

a 夏天 提交于 2021-02-11 12:11:54
问题 I'm trying but failing to write a regex to grep for lines that do not begin with "//" (i.e. C++-style comments). I'm aware of the "grep -v" option, but I am trying to learn how to pull this off with regex alone. I've searched and found various answers on grepping for lines that don't begin with a character, and even one on how to grep for lines that don't begin with a string, but I'm unable to adapt those answers to my case, and I don't understand what my error is. > cat bar.txt hello //world

How do I escape a single quote inside single quotes in jenkins-pipeline bash command

倖福魔咒の 提交于 2021-02-11 12:11:53
问题 in jenkins-pipeline, I'm trying to use SED to append the following line to the end of a file. sh "sed -i '\$ s/\$/ public_file=\\/var\\/lib\\/jenkins\\/workspace\\/test-project\\ ansible_ssh_common_args='-o StrictHostKeyChecking=no' /' file.txt" but I can't figure out how to escape the below line in my Jenkins file to make it work. ansible_ssh_common_args='-o StrictHostKeyChecking=no' I've already tried the following, which works in katacoda playground, but not in jenkins pipeline. '"'"'-o

Moving files into new subdirectory, except for existing folders?

房东的猫 提交于 2021-02-11 12:05:28
问题 A Redditor had written me a great script that allowed me to move all the files in a series of folders into a new subdirectory in all those folders called New. However, I also have pre-existing folders (namely just 1 called "Journals") that have had their files moved into a subdirectory called New, as well. How would I modify the following script (on Windows) to not touch any folders within the folders, or perhaps not touch any folder called Journals? For example, the current directory looks

Grep for lines not beginning with “//”

こ雲淡風輕ζ 提交于 2021-02-11 12:04:38
问题 I'm trying but failing to write a regex to grep for lines that do not begin with "//" (i.e. C++-style comments). I'm aware of the "grep -v" option, but I am trying to learn how to pull this off with regex alone. I've searched and found various answers on grepping for lines that don't begin with a character, and even one on how to grep for lines that don't begin with a string, but I'm unable to adapt those answers to my case, and I don't understand what my error is. > cat bar.txt hello //world

C++: Read from stdin as data is written into pipe

浪子不回头ぞ 提交于 2021-02-11 11:22:01
问题 I have two C++ programs: one that prints a message to stdout, and the other that listens to stdin and prints all content from the stream. They are named out and in respectively. out.cpp: #include <iostream> using namespace std; int main() { cout<<"HELLO"; usleep(1000000); cout<<"HELLO"; } in.cpp: #include <iostream> using namespace std; int main() { string input; while(cin>>input) { cout<<input; } } As it currently stands, piping the data from out to in waits for two seconds, then prints