bash

BSD grep returning incorrect results

When executing grep on OSX my results are incorrect. I’m looking for the offset of a substring with several matches, using -aob. ‘a’ indicating that i’m using strings, ‘o’ only showing the result, and ‘b’ for the byte offset. echo “ABDABCABC” | grep -aob “ABC” With the output: 0:ABC ABC When in fact the output should be: 3:ABC 6:ABC By…
Read more

Counting words and characters in Bash without wc

I have a variable set like this: sentence=”a very long sentence with multiple spaces” I need to count how many words and characters are there without using other programs such as wc. I know counting words can be done like this: words=( $sentence ) echo ${#words[@]} But how do I count the characters including spaces? Source: bash

Calculate Median in Multiple Rows

I have a file name numbers, simply contain bunch random numbers 1 2 3 7 5 9 2 2 9 5 4 5 7 2 6 I have to create a script that find the median for each row, and here is my code: while read -a row do for i in “${row[@]}” do length=`expr ${#row[@]} % 2` if […
Read more

execl in child process works for only in specific cases

I have been bussy for the last five hours with this problem so I hope someone can help me out. In my C++ program (which I develop in QTcreator on lubuntu) I want to run airodump-ng in the child process of my program. The output of airodump-ng should be directed to the STDOUT of the parent proces. This works with…
Read more

Issue running sed to replace a string in file

I am trying to run the following sed command on this line: entry({“servicectl”}, alias(“servicectl”, “status”)).sysauth = “Admin” sed -i~ -e ’18 { s/= “(.*)”/= {“”}/; # Add curlies to a single entry. s/}/,”‘”$entry”‘”}/ # Add the new entry. }’ “$file” I want to replace “Admin” with {“Admin”, “$entry”} THe problem I see is in the Regular expression to search is…
Read more

Shell script prints more values than I want

This is the script: OLDIFS=$IFS IFS=”,” while read f1 f2 f3 f4 do echo $f4, done < users_test.csv IFS=$OLDIFS And the target file looks like this: Type,Name,Email,User ID,Signed up,Last seen,Web sessions,Country,City I need to get only the 4th value (under User ID). But with the script that I have written, I get the 4th value and everything after it. I…
Read more