# Tag Info

## New answers tagged shell-script

0

Replace: find /Users/benjaminbaker/Documents/Thesis/Data/EIA_AMI/Test/ -iname '*$i*' -maxdepth 1 -type f -exec mv -n {} /Users/benjaminbaker/Documents/Thesis/Data/EIA_AMI/Test/$i/ \; With: find /Users/benjaminbaker/Documents/Thesis/Data/EIA_AMI/Test/ -maxdepth 1 -iname "*$i*" -type f -exec mv -n {} ... 0 You can create a function and use it through the awesome client tool. First, create a function and add it to your rc.lua file : function spawn(command, class, tag, test) local test = test or "class" local callback callback = function(c) if test == "class" then if c.class == class then awful.client.movetotag(tag, c) ... 1 use getopt to enable long and short options, as well as -rdn option concatenation parsed_options=$( getopt -o r:d:h --long rotate:,device:,help --name "$(basename -- "$0")" -- "$@" ) # option name followed by a single colon indicates the option takes # a required argument if [$! -ne 0 ]; then echo "Exiting" >&2 exit 1 fi eval set -- ...

0

I would go with grep -A 3 -B 1 '<subTag1>1300</subTag1>' infile.xml > outfile.xml -A select lines after context. -B select lines before context which outputs nicely <main tag> <subTag1>1300</subTag1> <subTag2>BBcycle</subTag2> <subTag3>55</subTag3> </main tag>

0

It works the same way as return in a function or sourced shell script. # EXIT $echo$(exit 12) $? >>> 12 # FUNCTION func() { return 12 }$ echo $(func)$? >>> 12 # More simple echo return 12 $? >>> 12 Where$? is exit code of the last performed action.

0

Use Github for Windows. It contains all the Unix environment executables. https://github-windows.s3.amazonaws.com/GitHubSetup.exe

3

In bash, you should use $(...) to store output of a command, not &(...). aux=&(...) is interpreted as aux= and (...) connected by &, i.e. it clears$aux in the background, and runs the bc in a subshell.

0

I had to modify your regex to make it valid but this sed command prints only the lines that match: $sed -nr '/[.].*[a-zA-Z0-9][a-zA-Z0-9-]+([.][a-zA-Z]{2,15})?$/p' file example.example.example.org 01.001.11.00.example.com asdf-asdf-asdf-www.example.net example.example.co.uk example.photography example.info How it works -n This tells sed not to print a ...

0

This isn't pretty, but it works: Get-ChildItem \\path\to\folder -Filter '*.txt' | foreach { $text = Get-Content$_.FullName $text =$text -replace 'a2','test' $text =$text -replace 'a4','foo' $text | Set-Content$_.FullName } The problem with your script is that you need to Set-Content in the ForEach-Object loop.

0

I used '//apps/matlab2014b$/bin/win64/MATLAB.exe' -r filename and it worked in my shell script. DONOT use .m in the filename above. 0 Answer #1: Race conflict head nofile text1 1> output.txt 2> output.txt # -- I know this won't work.` This actually works, even if not as you expected and doesn't comply your purpose. You have 2 file-descriptors that will be redirected independently to the same output file with > output.txt. One file-descriptor will act faster: it will create ... 2 You can do this with inotifywait utility (from inotify-tools package, under Debian at least). inotifywait can take event names as arguments and wait for them to happen on monitored file or directory, before returning. In your case, you would need to use the delete_self event, to indicate that you want the program to return when monitored file is deleted. ... 0 As Windows and Mac is unfortunately incompatible I wrote two files. script_mac.command for Mac script_win.bat for Windows For Mac: As I'd like to have an executable file (script runs, when double clicking) opened by terminal (Mac) I had to type in terminal chmod +x script.command. Furthermore, I'd to choose the default app being terminal for opening ... 0 On Windows there's cmd on Mac there's the (bash) shell. They are incompatible - you could use python instead. The bwst way is just to create a .bat/.cmd and a .sh file. 0 Using GNU Parallel it looks like this: (find ... -type f | parallel -j1 cat {}';'echo ) > t.txt GNU Parallel is a general parallelizer and makes is easy to run jobs in parallel on the same machine or on multiple machines you have ssh access to. And it can also replace many for loops as in this case. If you have 32 different jobs you want to run on 4 ... 0 You need an XML parsing tool. xmlstarlet is my favourite. After fixing up your invalid XML, we have$ xmlstarlet ed -d '//main_tag[subTag1 != 1300]' file.xml <?xml version="1.0"?> <root_tag> <main_tag> <subTag1>1300</subTag1> <subTag2>BBcycle</subTag2> <subTag3>55</subTag3> ...

1

Shell variables only resolve between Double Quotes ("). sed "s/$WORKDIR/$ARCHIVE/ig" test.dat > abc (Double quotes) Would work if not for the forward slashes. Sed can use any character to delimit those input fields and forward slash is perhaps not the best choice due to it's use for directory paths. For example you can use this instead: sed ...

0

If you are planning on expanding this script - which, from your question about a database, you are - I would recommend paramaterising as much as possible. I would also recommend using ffmpegthumbnailer to generate the thumbnails, which should be a simple yum install ffmpegthumbnailer / apt-get install ffmpegthumbnailer away. Check the options- in my script ...

0

I don't know what the standard shell is in Aix, but bash is available and supports edited expansion of variables. If your full name is in the variable FileName, then ${FileName##*/} displays the name with all leading characters deleted as far as the last /; by contrast${FileName#*/} deletes up to the first /, while ${FileName%/*} deletes trailing ... 0 The following applies to all strings in a shell, not just filenames, and is far easier than cut because you don't need to know how many fields there are before the one you want:$ foo=/path/to/file/split/by/slashes.txt $echo${foo##*/} slashes.txt This uses the 'greedy trim', i.e. trim everything until the last '/' as described here: ...

1

If you are in a Linux-like environment you can use the basename utility: basename $(<your_file) 0 If you know the exact format of the directory structure and it won't alter, you can use cut:$ cut -f6 -d '/' file.txt Here uses cut to treat the directory separators as a delimiter and extract the 6th one. If instead all you know is it is the last part of a line but don't know the directory structure, you can use rev as well: $rev file.txt | cut -f1 ... 0 use this command cat text_file_name | cut -d '/' -f 6 1 The stderr is not redirected to the file. Most probably you need ./script.sh > results.txt 2>&1 to redirect both to results.txt. Note that ./script.sh 2>&1 >results.txt is something different, as it redirects stdout to file and stderr to the non-redirected stdout. And of course you can substitute &1 for a different file name. ... 0 Make sure you redirect all output to the text file. stdout with > stderr with 2> See more here and here. Note that the script should start with: #!/bin/bash 2 bash now allows here strings, eg: var="Some random string" grep -e "Some" <<<"$var"

Top 50 recent answers are included