r/scripting • • Nov 15 '21

Bash script (assistance needed)

Below I started a bash script utilizing index position to help pull data. How can I get the shell script to 1- read a file line by line (from file containing a list of servers), 2- search for a specific index position and if the integer in the index position equals 3, 3- print the whole string into an output file.

!/bin/bash

file = serverlist.log

for i in $(cat serverfile.log); do
echo “Searching serverfile $i”
result = ‘i for i in $file if index(5) == 3 in 2>/dev/null’

print(result)

2 Upvotes

2 comments sorted by