Tag Info

New answers tagged

0

bash now allows here strings, eg: var="Some random string" grep -e "Some" <<<"$var"


1

echo $var | grep -e "Some" is actually the right approach. When piping the output through grep with |, it no longer appears on the console. From the man page of Bash: Pipelines A pipeline is a sequence of one or more commands separated by one of the control operators | or |&. The format for a pipeline is: [time [-p]] [ ! ] command [ ...


1

You can use the environment variables PWD and HOME: $PWD is the current working directory, while $HOME is the current user's home directory. You can precede the executable statements in your script by: if [ "$PWD" != "$HOME" ]; then exit; fi You can optionally add an error code to the exit command, in case the calling shell wants to check the success or ...


1

Try cut -d'.' -f-3 <file_name.txt -d defines the "field delimiter", Do put it inside '-quotes, so it is "safe from bash" (some characters has special meaning in bash, this is the means to avoid trouble) Effect here -> split at . chars. -f defines which "fields" to keep, => -3 => Effect here: all from the beginning up to and including the third. man ...


1

You can use a positive lookahead regex: echo "g-82.text.text1.fr.worker1" | grep -Po '.*(?=.fr)' echo "g-xx.yyyyyy.zzzz.fr.worker2" | grep -Po '.*(?=.fr)' Documentation here: http://www.rexegg.com/regex-lookarounds.html


1

Use the sed command. sed 's/.fr.*//' file_name.txt Explanation: sed will remove the part of the line matching the regular expression .fr.* from each line in the file, thus leaving the content before .fr. .fr.* means .fr. followed by anything.


4

Unfortunately - this is like asking which car is best suited to people who drive... there is and never will be a definitive answer.. That said, there are some good generalisations you can make: For administering pretty much anything Windows 7/2008R2 and newer - PowerShell is a very good choice. The reason for this is that it leverages a lot of the power ...


1

Kindly refer to the solution here I am posting that solution again @echo off set f1=1.txt set f2=2.txt set "sep= " % tab % ( for /f "delims=" %%a in (%f2%) do ( setlocal enabledelayedexpansion set /p line= echo(!line!!sep!%%a endlocal ) )<%f1%


0

Yes this can be done. Since your using Windows I'd recommend looking into the Windows Event Scheduler. Official Microsoft documentation can be found HERE. Since you don't provide any details about where the stream is coming from I can only give you general guidance. But it's going to look something like this. Setup Windows Event Scheduler to run a ...


0

I can't give you a very detailed answer with the information provided. The basic idea will be to set up associative arrays that store the messages and use the right one depending on the values stored in your variables. Something like this: ## Set up 2 associative arrays with the server names and messages messages_macbook=( ["Server1"]="foo" ...


0

Source http://www.ubuntu.com answer csh - which $SHELL still gives /bin/bash by geirha The SHELL environment variable does not indicate what shell you are currently using. It is simply set, when you log in, to the value of the login shell field of /etc/passwd, which in your case is /bin/bash. If you want to change your login shell, run chsh ...


0

If running in Linux the below should work. Let me know in which Unix OS you are running this script. find /home/ah5024331/f1 /home/ah5024331/f2 /home/ah5024331/d1 /home/ah5024331/d2 /home/ah5024331/f1 /home/ah5024331/f2 /home/ah5024331/d2 -type f -exec cat {} \; -exec echo -n "" \; > /home/ah5024331/op.txt


0

You could simply write a Perl script to handle the job. It's less messy than Bash. Here's an example of such a script. It calculates the file size reduction between the original and compressed file. #!/usr/bin/env perl use strict; use warnings; die "You must define at least 2 files to compare!\n" unless defined $ARGV[0] && defined $ARGV[1]; die ...


0

Create a dummy file with a newline. echo -n "" > /tmp/newline.txt Now execute your script as below. (find /home/ah5024331/f1 /home/ah5024331/f2 /home/ah5024331/d1 /home/ah5024331/d2 /home/ah5024331/f1 /home/ah5024331/f2 -type f | xargs -i cat {} /tmp/newline.txt ) > t.txt


0

Try this: #!/bin/bash for f in $(find /home/ah5024331/f1 /home/ah5024331/f2 \ /home/ah5024331/d1 /home/ah5024331/d2 -type f) do cat "$f" >> t.txt echo >> t.txt done This will append a new-line after the end of each file, however, if any of these files already have a new-line at the end, you'll see an extra blank line in the output ...


1

Is the program really located in /home/test? With ordinary Linux distributions, that would be an odd place to put a program. Assuming that you mean your home directory, the usual location would be /home/ plus your user name, so the program would be at /home/researcher/test. Or if it's in the home directory for root, /root/test (note: no "home" there). So ...


0

Search for apt-get and "non-interactive" or "unattended" You can find an answer here: http://serverfault.com/q/227190


1

The following line of bash will do, assuming you just want to get rid of these files: for i in $(grep -lrI bar); do mv -i ./backup/`basename $i` $i; done


1

You could try with the following format Syntax : grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g' The example would be : grep -rl 'windows' ./ | xargs sed -i 's/windows/linux/g' This will search for the string windows in all files relative to the current directory and replace 'windows' with linux for each occurrence of the ...


0

Quick and dirty. Not usable on huge server infrastructures due to the high performance need on huge files. But for reasonable file sizes viable: while read file2_var ; do if [ "$file2_var" != "$(grep $file2_var path/to/file1)" ]; then echo $file2_var >> file3.txt; fi ; done < path/to/file2 I am just fooling around with scripts for a month and this I did ...


0

Use split, it's part of coreutils. It can take stdin and split it into chunks (based on chunk size, or number of lines, etc.). Example: app | split --bytes 1G - /var/logs/put-prefix-here Note dash (-) instructs "split" to use stdin instead of file.


0

We could use a xsl-document doThis.xsl and process the source.xml with xsltproc into a newFile.xml. The xsl is based on the answer to this question. Put this into a doThis.xsl file <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="UTF-8" ...


0

Have you tried mapping a drive in file explorer? Assuming the issue is with needing a different user's credentials to access the server's mapped location, try this: (This is more of a work-around than a solution, and exploiting a bug rather than a feature, but see below) In Windows, add the remote network share as a mapped drive When in the map network ...


0

I got the first part working, that is all csv files in each sub folders are combined into a csv file each. So, I have 20 csv files. The error was the single %. It should be %%G. FOR /D /R %%G in ("*") DO ( cd %%G COPY *.csv new.csv )


1

If all of the files really are valid CSV, then amending the last line to loop over the files in the current folder using variable %H, change the copy to: TYPE %H >>new.csv Should work (not fully tested I'm afraid). However, a better approach would be to use PowerShell since that has cmdlets to handle CSV input and output and so it would be able to ...


1

The --client-connect script is run as the non-privileged OpenVPN user specified by the --user parameter. You can verify this by adding these lines to the top of your --client-connect file and reviewing the output written to /tmp/ov.log after a successful connection #!/bin/bash exec >>/tmp/ov.log 2>&1 chmod 666 /tmp/ov.log 2>/dev/null echo ...


3

Your sed one-liner substitution seems to already work as you intend: $ cat t.txt Hello world types="" Mario types="Game" $ sed '1,/types=""/s/types=""/types="program"/' t.txt Hello world types="program" Mario types="Game" It might be worth editing your question to show what you get when you run your sed command (without the -i option so that the results ...


1

cut -d'|' -f1-14 myfile This works fine! Simple cut would do no need for awk or sed.



Top 50 recent answers are included