1

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

4

2 回答 2

2

使用 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

我阅读了您对 hek2mgl 答案的评论——这些要求必须在问题本身中。

于 2013-10-30T00:34:54.307 回答
2

凭借sed其:

sed -n 's/.*\(2z\(\(.*\)\.\(.*\)\)n9\).*/variable 1 = \L\3\nvariable 2 = \L\4/p'  your.file 

输出:

variable 1 = test1
variable 2 = test2
于 2013-10-29T23:03:54.383 回答