Reputation: 1
I am trying to write a one liner and cannot figure out what I am doing wrong. I am trying to use the following command:
cat testadds | cut -f 1 -d "," | xargs -ifoo /bin/bash -c "cat testadds | cut -f 2 -d \",\" | xargs --replace=addr /bin/bash -c \"cat testadds | cut -f 3 -d \",\" | xargs --replace=num /bin/bash -c \"cat testmdl | sed 's/DUMMY/foo/g' | sed 's/IP1/addr/g' | sed 's/IP2/num/g'\"\""
I get nothing for an out put, my testadds
file is set up as follows:
dev,IP1,IP2
when I do this with only 2 xargs
, it works fine, but when I add the 3rd and last xargs
, it provides no output. I am wondering if there is a limit to how many times you can use xargs
when cating a file.
I guess the expected input is from a file that has multiple devices. the input would be testdevice,1.1.1.1,2.2.2.2
The exepected output would be:
-deviceSystemSoftware 'device:testdevice' '6500 7-SLOT OPTICAL SW:1021'
-deviceCname 'device:testdevice' 'PRIORITY SLA - identifier - testdevice'
-deviceDateAdded 'device:testdevice' '2017-02-24'
-deviceNotes 'device:testdevice' 'BTWB100269 - testdevice'
-hier 'nib:opr|0 group:Openreach group:TSO'
-hier 'nib:opr|0 group:Openreach group:TSO group:Ciena'
-hierUnique 'nib:opr|0 group:Openreach group:TSO group:Ciena device:testdevice'
-createEntity 'service:snmp-trap-handling{device:testdevice}CA|0[+opr-ciena-6500-alarms|+Nocol]'
-createEntity 'service:configuration-tracking{device:testdevice}opr|0[ciena6500]'
-createEntity 'interface:testdevice|COLAN-1-X'
-entityDescription 'interface:testdevice|COLAN-1-X' 'COLAN-1-X'
-createEntity 'address:testdevice|COLAN-1-X|1.1.1.1'
-devicePrimaryInterface 'device:testdevice' 'interface:testdevice|COLAN-1-X'
-deleteEntity 'address:testdevice|mgmt|1.1.1.1'
-deleteEntity 'service:ippingmon{interface:testdevice|mgmt}opr|0[]'
-deleteEntity 'interface:testdevice|mgmt'
-createEntity 'interface:testdevice|SHELFIP'
-entityDescription 'interface:testdevice|SHELFIP' 'SHELFIP'
-createEntity 'address:testdevice|SHELFIP|2.2.2.2'
Hopefully this helps
What I am trying to accomplish is to modify the files to display them as the expected output. This is to add it to my monitoring system. Sorry, this is the first time I have ever done this, so I apologize for any lack of information.
Upvotes: 0
Views: 404
Reputation: 531155
You just need a single while
loop, which even on one line is shorter than your attempt (and far less expensive, since there are no external programs started; everything is done by built-in commands):
# while IFS=, read -r dev ip1 ip2; do printf "-createEntity 'address:%s|%s|%s'\n" "$dev" COLAN-1-X "$ip1" "$dev" SHELFIP "$ip2"; done < input.txt
while IFS=, read -r dev ip1 ip2; do
printf "-createEntity 'address:%s|%s|%s'\n" \
"$dev" COLAN-1-X "$ip1" \
"$dev" SHELFIP "$ip2"
done < input.txt
Upvotes: 1