|
Bash Script That Will Cut The File Up
Question:
I have a file that has one line in it, and looks like this:
Code:
-a test.example.com -a next.example.com -a last.example.comI'm trying
to code a bash script that will cut the file up, and only give me the *.example.com
portions. I imagine I'll need the cut command (or multiple cut commands).
Something like this:
Code:
list=`cat thefile | cut -d"-"I know that's not a working example,
but I wanted to see if anyone else had attempted something similar before
and could give me an example. The number of entries can be variable and
the domain names can of course be anything, but it will always be in the
same format and on one line.
Solutions:
Say for example
Code:
$ a="-a test.example.com -a next.example.com -a last.example.com"
$ set -- $(echo ${a//-a/})
$ echo $@
test.example.com next.example.com last.example.com
$ echo $1
test.example.com
$ echo $2
next.example.com
$ echo $3
last.example.comin a file
Code:
while read -r line
do
set -- ${line//-a/}
echo $1
echo $2
echo $3
done < "file"
PS: That will gets you running in the right direction. I think, if you
do not know the number of entries in the file, you can play and get that
from "echo $@" I think.
Have a Linux Problem
Linux Forum - Do
you have a Linux Question?
Linux Books
Linux Certification,
System Administration, Programming, Networking Books
Linux Home: Linux
System Administration Hints and Tips
(c) www.sap-basis-abap.com All material on this site is
Copyright.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
All product names are trademarks of their respective
companies.
The site www.sap-basis-abap.com is in no way affiliated
with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.
|