Tag Info

New answers tagged

0

If I were doing this in bash, I'd do it something like this: line=$(grep -m1 -n ERROR the_file | cut -f1 -d:) if ((line <= 20)); then cat the_file; else tail -n+$((line-20)) the_file fi which uses grep with the "show line numbers"ยท option to get the line number of the match, and then tail -n to print the starting with the 20th previous line, being ...


1

If I am interpreting your question correctly I believe you are asking how to force a pseudo-tty allocation when opening the ssh connection. this should do what you want : ssh -t root@hostname 'su - dba' Not sure why you need that....


0

awk: I'm just keeping 5 lines for this demo, adjust the "keep" value to 20 { seq 10; echo ERROR; seq 6; } | awk -v keep=5 ' /ERROR/ { for (i=keep; i>=1; i--) print lines[i] # the stored lines print # the current line while (getline > 0) print # all the remaining lines } { # ...


3

You can do this with grep's -B (--before-context) option: grep -B 20 error filename


3

#/bin/bash if [ "$SourceFile" -nt "$TargetFile" ]; then echo "SourceFile is newer than Targetfile" fi -nt means "newer than". I've added quotes around the file names because if you need quotes on the echo, tehn you also need quotes on the file names...


0

I am not too familiar with pssh. Do you get the same error if using GNU Parallel: #!/bin/bash parallel -j10 --slf hosts.txt --nonall "$@" Put the username in hosts.txt: myuser@host1 myuser@host2


2

this answer might cover it Spaces in Linux environmental variables? You put the environment variable in double quotes. example demonstrating that below I am doing ls 'asdf asdf' which is ls on one file 'adsf asdf' with a space in the filename. I want to do it with a variable. You see with double quotes it gets the result. With no quotes it treats the space ...


-1

Prepend any Space character with Escape string, so the Space will be in the string as '\ ' (backslash + space). Hope this help.


0

So, after a few unfortunate tries, here's what resolved the issue for me. I made a powershell-clean.bat file, containing the following echo 'this won't touch Binaries subfoldrs, only (Build, Intermediate, Saved). powershell.exe -ExecutionPolicy Bypass -Command "ls -Recurse -Include Build, Intermediate, Saved | rmdir -Force -Recurse" I had to spare ...


1

@echo off for /F %%i in ('dir /b /a:d') do ( dir /b /d %%i\build 2>NUL && echo rmdir /q /s %%i ) Remove the echo before rmdir if you find that it does what you want? WARNING this is a bit untested so be careful maybe better to echo to a file and run from there after edit.


0

This answer given in the comment above by l0b0 is correct. I would have marked it as the correct answer, but it is a comment, so I can't: There are many duplicates on USE, but they can be hard to find. Look at for example Appending to same array in various loops, only last values remain Bash 4 There are two solutions given there. For me actually only the ...


2

To run vlc as another user, use: #!/bin/sh su user -c 'vlc -vvv bigbuck.mp4 --sout "#rtp{dst=99.195.203.99,port=8090,sdp=rtsp://99.195.203.99:8091/test.sdp}" & If you don't need the graphic interface, you might consider using cvlc in place of vlc: #!/bin/sh su user -c 'cvlc -vvv bigbuck.mp4 --sout ...


0

Simple example of escaping quotes in shell: $ echo 'abc'\''abc' abc'abc $ echo "abc"\""abc" abc"abc It's done by finishing already opened one ('), placing escaped one (\'), then opening another one ('). Alternatively: $ echo 'abc'"'"'abc' abc'abc $ echo "abc"'"'"abc" abc"abc It's done by finishing already opened one ('), placing quote in another quote ...


1

Loops are run as a separate process so variables inside a loop are destroyed when the loop ends. If you can use Python, it does keep variable changes inside loops. currd = ["dir1"] is_this = "n" datalines = ["dir1"] print is_this # checking variable for lines in datalines: if lines != "".join(currd): print lines + " is not current dir" ...



Top 50 recent answers are included