I know some IDE's support this feature, but does anyone know how to activate brace lines? I don't know exactly what they're called, but they look kinda like this:
if(numOfSomething > 8)
{
| if(blah == true)
| {
| | blah = false;
| | //whatever
| }
{
Anyone know is visual studio supports these and how to turn them on?
I have "Indent Guides" extension for that behaviour you say:
http://visualstudiogallery.msdn.microsoft.com/e792686d-542b-474a-8c55-630980e72c30
Related
greenh='\e[2;30;42m$&\e[0m/g'
yellowh='\e[2;30;43m$&\e[0m/g'
aquah='\e[2;30;46m$&\e[0m/g'
function recolor() {
perl -pe "s/$1/$2"
}
i use this to recolor text
EXAMPLE:
cat file.txt | recolor WHATEVERWORD $greenh
Is there a way that i can include the $ in the function so i can use it like
cat file.txt | recolor WHATEVERWORD greenh
I tried
function recolor() {
perl -pe "s/$1/$$2"
}
function recolor() {
perl -pe "s/$1/\$$2"
}
Both of them just break the function altogether...
That's really the wrong approach; you're piling a bunch of hacks together that all "leak" through to different layers. (For example, consider recolor 'x//g;#' greenh, which is intended to take occurrences of x//g;# and color them green, but which actually takes occurrences of x and deletes them; or recolor foo blueh, which is intended to take occurrences of foo and color them blue, but which actually doesn't work because your function secretly depends on a global variable being set and the user didn't define $blueh.)
I think you're better off just defining individual functions:
greenh() { pat="$1" perl -pe 's/$ENV{pat}/\e[2;30;42m$&\e[0m/g' ; }
yellowh() { pat="$1" perl -pe 's/$ENV{pat}/\e[2;30;43m$&\e[0m/g' ; }
aquah() { pat="$1" perl -pe 's/$ENV{pat}/\e[2;30;46m$&\e[0m/g' ; }
If you do want a single recolor function, then you're better off defining the colors inside it:
recolor() {
perl -e '
my $prefix =
{
"greenh" => "\e[2;30;42m",
"yellowh" => "\e[2;30;43m",
"aquah" => "\e[2;30;46m",
}->{$color};
die "Unrecognized color $color" unless $prefix;
while (<>) {
s/$pat/$prefix$&\e[0m/g;
print;
}
' -s -- -pat="$1" -color="$2"
}
(For completeness' sake, though, I should mention that Bash does support variable indirection; if $2 is greenh, then ${!2} is whatever $greenh is. But that feature is usually best avoided, and your example is exactly why.)
As you were already told (when your prior instance of this question was closed as a duplicate) -- to implement the replacement you're looking for in bash, without regard to what a best-practice Perl solution would be, you'd use ${!varname} to look up the variable whose name is stored in varname. In this case, you want to look up the variable whose name is stored in $2, so you'd use ${!2}:
aquah='\e[2;30;46m$&\e[0m/g'
recolor() { perl -pe "s/$1/${!2}"; }
echo "hello" | recolor lo aquah
...which successfully colors lo in aquah. See BashFAQ #6 for details.
That said: Using string concatenation to dynamically generate code is never a good idea. Don't do this. It's much safer to pass your values into perl as environment variables or separate argv elements, instead of substituting them into code.
First thing - sorry for a bit misleading title, not sure how to describe this yet.
Basically, I have a list of keywords and I want to fetch the number of documents google returns per query. I have created the following awk script:
{
x = ""
for(i=1;i<=NF;i++) {
if(i==NF) {
x = x $i
} else {
x = x $i "+"
}
}
tab = "777" # id of an existing chrome tab as reported by 'chrome-cli list tabs'
system("chrome-cli open http://www.google.com/search?hl=en\\&q="x" -t " tab)
system("chrome-cli source -t " tab " | grep '<div id=\"resultStats\">About .* results<nobr>' | head -1 | sed -e 's/.*>About \(.*\) results<nobr>.*/\1/' | awk '{print $1\"\t"x"\"}' >> freq.log " );
system("cat freq.log" );
system("sleep 0.5");
}
What happens here is that I firstly replace all spaces with + signs, execute chrome-cli command to open chrome at that particular window, download source code and parse the number between "About" and "results" strings out and append the result to freq.log. This, however, outputs the following string into the file (for term alarm):
"})();</script><div alarm"
When I execute the same command from iOS terminal, I get a correct number (returns 127.000.000):
chrome-cli source -t 777 | grep '<div id="resultStats">About .* results<nobr>' | head -1 | sed -e 's/.*>About \(.*\) results<nobr>.*/\1/'
So my problem basically is that while everything works correctly from the terminal, as soon as I move my code to awk and execute it using a call to system, something breaks and regex doesn't work anymore.
You've properly escaped " in your system commands, but it looks like you haven't escaped the \ in your sed command. By the time it reaches sed, \( is being seen as a plain (.
Try changing your system statements to print and you'll see what I mean.
Worst case scenario, you can bundle the series of system commands into a shell script and have awk call it instead... but in that case, you might as well entirely use shell scripting instead of awk.
when I type this directly into the terminal - it works as expected and returns 0 if the app is not running, and 1 if it is.
lsappinfo list | grep -v grep | grep bundleID | grep com.test.myapp | wc -l
However, when I use the code below (swift 3 - macOS), it says it is an unrecognised command?
// DECLARE TASK
let task = Process()
// DEFINE THE PATH
task.launchPath = "/usr/bin/lsappinfo"
// DEFINE THE ARGUMENTS
task.arguments = ["list | grep -v grep | grep bundleID | grep com.test.myapp | wc -l"]
// DECLARE outputPipe
let outputPipe = Pipe()
// RUN THE TASK
task.launch()
// DECLARE data
let data = outputPipe.fileHandleForReading.readDataToEndOfFile()
// DECLARE output AS THE UTF-8 STRING OF THE TERMINAL'S OUTPUT
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
print(output!)
if output == "0" {
print("App is not running!")
} else {
print("App is running!")
}
// PAUSE UNTIL COMPLETED
task.waitUntilExit()
Can someone please tell me where I have gone wrong, as I am new to Swift, and still struggling to get my head around the language / syntax.
Thank you all in advance.
Piping operations are not arguments to the process, they are instructions to a shell to connect several separate processes. If the task construct in swift expects a process and a set of command-line argument, then one way to do this here would maybe be to launch the bash binary, and then put -c "lsappinfo list | grep -v grep | grep bundleID | grep com.test.myapp | wc -l" as the full set of arguments. That way, you would let bash sort out what's needed to accomplish the piping.
I seem to be to stupid to parse some HTML Files with Bash. We have some files which have lines like:
var A4_total = 2018 + 4730;
var Other1_total = 3242 + 3828;
(They tell us how many pages the Printers have printed).
I need to calculate the first two Values together (2018 and 3242). My Approach is:
hilfsvar1=$(echo `grep -F var\ A4_total StatCntMedia.htm | sed 's/var\ A4\_total\ \=\ //g'` | sed -ne "s/^[^=]\++//p" | sed 's/;//g'); hilfsvar2=$(echo `grep -F var\ Other1_total StatCntMedia.htm | sed 's/var\ Other1\_total\ \=\ //g'` | sed -ne "s/^[^=]\++//p" | sed 's/;//g'); echo "$hilfsvar1 + $hilfsvar2" | bc
This will fail. The two variables do have the right content:
[User]# echo $hilfsvar1
4730
[User]# echo $hilfsvar2
3828
But this is where I can't get forward:
[User]# echo "$hilfsvar1 + $hilfsvar2"
+ 3828
(Sorry for my scripting, I don't have deeper knowlede of Script languages :) ) - I would be happy to resolve this in another way if someone does have a solution.
Thanks in advance, Jonas
It sounds like this might be what you're looking for:
$ awk '{sum[4]+=$4; sum[6]+=$6} END{print sum[4], sum[6]}' file
5260 8558
If not, update your question to show expected output.
It seems like you're probably on completely the wrong track though and trying to do somethign in shell that should be done entirely in awk.
Try something like:
awk '/A4_total|Other1_total/ {print $4+$6}' StatCntMedia.htm
Output:
6748
7070
search for either A4_total or Other1_total, add 4th and 6th field separated by space and display the output.
"/home/chief/project/public/system/uploads/000/000/001/original/1/1.flv
to this:
/system/uploads/000/000/001/original/1/1.flv
str = "/home/chief/project/public/system/uploads/000/000/001/original/1/1.flv"
chopped = str.sub(/.*\/public/, "") #=> "/system/uploads/000/000/001/original/1/1.flv"
This will remove everything to the left of public (including /public). This way your code isn't specific to one location, but rather it is more portable in that you can have anything in front of /public, and it will still strip the characters.
s = "/home/chief/project/public/system/uploads/000/000/001/original/1/1.flv"
s.sub("/home/chief/project/public", "")
This should do the trick.
You should specify in which language.
Using sed is trivial.
echo "\"/home/chief/project/public/system/uploads/000/000/001/original/1/1.flv" | sed -e 's-\"/home/chief/project/public--'