I am trying to write a script that takes one file and runs each lines as a string for the awk command which is executed on another file. Here is what I have at this point.
#!/bin/bash
FILE=$1
FILE_TO_SEARCH=$2
exec 4> "FILE_TO_SEARCH"
while read -ru 3 LINE; do
awk -v RS='' -v ORS='\n\n' "$LINE" <&4
done 3< "$FILE"
When I try to run the script I am getting:
./bashscript2.sh: line 8: read: read error: 3: Bad file descriptor
The file (FILE) that it would be searching would have contents like this as an example:
hostAbC
host123
host345
hostMos
hostDef
Which would then run the awk command on a file (FILE_TO_SEARCH) with contents that look like the one below except a lot more.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
id: urn:storageos:Initiator:
clustername = BLAHBLAHBLAH
creationTime = java.util.GregorianCalendar[
time=1490279415811
2017-03-23 14:30:15 811ms UTC
,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2017,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=23,DAY_OF_YEAR=82,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=2,HOUR_OF_DAY=14,MINUTE=30,SECOND=15,MILLISECOND=811,ZONE_OFFSET=0,DST_OFFSET=0]
host = URI:
hostname = hostAbC
inactive = false
ininode = 01:01:01:01:01:01:01:01
iniport = 01:01:01:01:01:01:01:01
internalFlags = 0
isManualCreation = true
label = 01:01:01:01:01:01:01:01
status = OpStatusMap {}
protocol = FC
registrationStatus = REGISTERED
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
id: urn:storageos:Initiator:
clustername = YADAYADAYADA
creationTime = java.util.GregorianCalendar[
time=1485972630239
2017-02-01 18:10:30 239ms UTC
,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2017,MONTH=1,WEEK_OF_YEAR=5,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=32,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=6,HOUR_OF_DAY=18,MINUTE=10,SECOND=30,MILLISECOND=239,ZONE_OFFSET=0,DST_OFFSET=0]
host = URI:
hostname = hostMos
inactive = false
ininode = 01:01:01:01:01:01:01:01
iniport = 01:01:01:01:01:01:01:01
internalFlags = 0
isManualCreation = false
label = 01:01:01:01:01:01:01:01
status = OpStatusMap {}
protocol = FC
registrationStatus = REGISTERED
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The awk command awk -v RS='' -v ORS='\n\n'
would then find the hostAbC
entry and return the full entry from space to space.
I can't figure out how to make it work.
read
would drop an error there, and I also can't reproduce that error either. (awk
will toss an error since the fd it's given to read is opened for writing, but that's not the error you posted here.) – ilkkachu Jan 20 '18 at 19:42