All Questions
10 questions
3
votes
1
answer
8k
views
Trying to put output of grep command into a bash array
If I run the following grep command I get the output I am expecting:
$ grep -o -E '/ |:|\\|<|>|\*|\?|\"| $' <<< '/home/ttwaro/temp/Test/This is a Test: Testing Number 1?/This is ...
0
votes
3
answers
2k
views
Remove elements from an array not containing a certain character
I have an array c_arr containing table columns with table aliases. But there are some elements in the array which are actually not columns and so they don't have the format alias.column_name.
I need ...
1
vote
2
answers
1k
views
Searching a file for a string in an array
I am trying to check if items in an array options are in a file $file using the following simplified code:
options=(
A
B
C
)
for i in "${options[@]}"; do
if grep -F $file &...
1
vote
1
answer
293
views
Bash Syntax for Using GREP to Extract Text from File and Store in an Array
I have recently upgraded from bash 4.2.46 to bash version 4.2.50
I had a script with the line:
mapfile -t my_array < <(grep ${ID} -w /etc/passwd | cut -d ":" -f 1,4,5)
where ID is an ...
0
votes
2
answers
8k
views
bash syntax error: invalid arithmetic operator (error token is ".google.com") when parsing through array
I have an array of domains that I am attempting to iterate through and check if a string from a file matches any of the domains in the array. However, when the for loop starts, I get an error
line ...
1
vote
2
answers
4k
views
Slicing the output of grep in bash
I'm trying to read a line of text in bash using grep, piped to tail to get the final line of the file, and then slice the first three "words" (i.e. dividing them using space) of that line as elements ...
2
votes
2
answers
5k
views
bash: convert array into string preserving white spaces
I am just trying to convert an array into string, while preserving the white spaces. This is what I have:
INPUT=$1
readarray -t arr < <(grep -o . <<< "$INPUT")
echo "${arr[*]}"
I ...
2
votes
3
answers
4k
views
bash array with space in element [closed]
I have a text log file
$ cat aaa
673 20160405 root "/path_to/gis/20160401/20160301_placement_map_org.dbf" ""
673 20160405 root "/path_to/gis/20160401/...
2
votes
2
answers
13k
views
grep using array values and make it faster
array[1] is a string pulled from a 30k lines CSV:
example:
samsung black 2014
I need match those lines with one of the values contained within an array (arrayItems).
arrayItems contains 221 values ...
1
vote
2
answers
6k
views
tar “Cannot stat: No such file of directory” when passing array variables [closed]
I'm trying to write a bash script that will create an archive (tar) of files in a directory. The file extensions need to be passed in as arguments when calling the bash script (./backup.bash pdf txt ...