Skip to main content

All Questions

Tagged with
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 ...
Tommy's user avatar
  • 31
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 ...
Mohammed Arif's user avatar
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 &...
Fergus's user avatar
  • 13
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 ...
CyberStems's user avatar
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 ...
john doe's user avatar
  • 956
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 ...
Henry Brice's user avatar
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 ...
HarshvardhanSharma's user avatar
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/...
Gao's user avatar
  • 21
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 ...
Kintaro's user avatar
  • 27
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 ...
willDurango's user avatar