1

I am running a script which will output a file called scServer.scs which looks something like this:

49138@bber0501u29b.bb2.cluster

2

Solution 1

Fluid Flow (Fluent)

Solution

Transient Structural

7443_bber0501u29b.bb2.cluster

27412@lic-server1.abc.ac.uk

Later in the script I need to reference the "49138" and "bber0501u29b.bb2.cluster" but they will be different every time I run the script. So after my script generates scServer.scs I need to extract those pieces of text and write them as variables?

  • 1
    is the data always on line 1? or the first one in the format of user@host? How do we know it's the right data? – Jeff Schaller Mar 7 at 15:58
  • It is always in that format, always on line 1, I belive RoVo has the answer – CFD-Tester Mar 7 at 16:17
3

If your data is always in the first line and in format user@domain, you can do this:

Extract the first line and use shell parameter expansion:

firstline=$(head -n1 file)
user=${firstline%@*}
domain=${firstline##*@}
0

Using read and awk:

read -r user domain < <(awk -F\@ 'NR==1{print $1,$2}' scServer.scs)

Will extract the first line of scServer.scs and separate two fields using @ as the field separator, assign the first field to the user variable and the second to the domain variable

0
g=`awk -F "@" 'NR==1{print $1}' filename `
y=`awk -F "@" 'NR==1{print $NF}' filename `


praveen@praveen:/tmp$ echo $g
49138
praveen@praveen:/tmp$ echo $y
bber0501u29b.bb2.cluster

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.