I
I
Ilya2020-08-13 14:54:23
bash
Ilya, 2020-08-13 14:54:23

Convert strings to columns bash?

There is a script which does whois and pulls out the necessary fields:
for as in $(cat as.txt):
do echo $as;
whois -h whois.radb.net -i origin $as > whoisas
route=`cat whoisas | grep route: | sed s/route:/\;/g`
descr=`cat whoisas | grep descr: | sed s/descr:/\;/g`
route6=`cat whoisas | grep route6: | sed s/route6:/\;/g`
echo -e $route"\n\r"$descr"\n\r"$route6
done>as.csv

But in csv they are dumped in rows, it is desirable to make them in columns
5f3529e79bb26295249403.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
unseriously, 2020-08-13
@unseriously

https://www.thelinuxrain.com/articles/transposing-...

S
Saboteur, 2020-08-14
@saboteur_kiev

while read; do
  RESULT=$(whois -h whois.radb.net -i origin $REPLY)
  route=$(echo "$RESULT"|grep -oP "route:\s*\K.*")
  descr=$(echo "$RESULT"|grep -oP "descr:\s*\K.*")
  route6=$(echo "$RESULT"|grep -oP "route6:\s*\K.*")
  echo "$REPLY;$route;$descr;$route6;"
done<as.txt>as.csv

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question