Reputation: 179
I have a File that contain too many charechter and symbols. I want to find an exact string and then cut it and give it to two variables. I have write it with grep
but i want to write it in **AWK**
or SED
.
Here is my example file :
.f@alU|A#Z<inCWV6a=L?o`A5vIod"%Mm+YW1RM@,L;aN
r^n<&)}[??!VcVIV**2zTest1.Test2n9**94EN~yK,$lU=9?UT.[
e`)G:FS.nGz%?@~k!20aLJ^PU-[@}0W\ !8x
cujOmEK"1;!cI134lu%0-A +/t!VIf?8uT`!
aC1QAQY>4RE$46iVjAE^eo5yR|
1?/T?<H5,%G~[|9I/c&8MY$O]%,UYQe{!{Bm[rRC[
aHC`<m?BUau@N_O>Yct.MXo[>r5^uV&26@MkYB'Kiu\Y
K(*}ldO:ZQnI8t989fi+
CrvEwmTQ80k3==,a'Jj9907+}NNy=0Op
"nzb.j-.i%z5`U*8]~@64sF'r;\x\;ylr_;q5F` A!~p*
first i want to find 2zTest1.Test2n9 then cut the first 2 and last two charechter and finally get Two Words without dot(.). First word will i send to one variable and second one two another Variable.
Note : I want to find 2zTest1.Test2n9 and then i want to cut it.
output :
variable 1 = test1
variable 2 = test2
Thanks
Upvotes: 1
Views: 269
Reputation: 247200
Using GNU awk:
read var1 var2 < <(
gawk 'match($0, /2[[:alpha:]]([^.]+)\.(.*)[[:alpha:]]9/, m) {
print m[1], m[2]
}' file
)
echo "var1=$var1"
echo "var2=$var2"
var1=Test1
var2=Test2
I read your comments to hek2mgl's answer -- those requirement need to be in the question itself.
Upvotes: 2
Reputation: 158230
With sed
its:
sed -n 's/.*\(2z\(\(.*\)\.\(.*\)\)n9\).*/variable 1 = \L\3\nvariable 2 = \L\4/p' your.file
Output:
variable 1 = test1
variable 2 = test2
Upvotes: 2