Extracting text from a file when I know its format
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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?
linux text-processing awk sed scripting
add a comment |
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?
linux text-processing awk sed scripting
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
add a comment |
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?
linux text-processing awk sed scripting
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?
linux text-processing awk sed scripting
linux text-processing awk sed scripting
edited Mar 7 at 15:57
Jeff Schaller♦
44.6k1162145
44.6k1162145
asked Mar 7 at 15:43
CFD-TesterCFD-Tester
103
103
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
add a comment |
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
1
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
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
It is always in that format, always on line 1, I belive RoVo has the answer
– CFD-Tester
Mar 7 at 16:17
add a comment |
3 Answers
3
active
oldest
votes
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##*@
add a comment |
Using read and awk:
read -r user domain < <(awk -F@ 'NR==1print $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
add a comment |
g=`awk -F "@" 'NR==1print $1' filename `
y=`awk -F "@" 'NR==1print $NF' filename `
praveen@praveen:/tmp$ echo $g
49138
praveen@praveen:/tmp$ echo $y
bber0501u29b.bb2.cluster
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f504948%2fextracting-text-from-a-file-when-i-know-its-format%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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##*@
add a comment |
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##*@
add a comment |
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##*@
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##*@
answered Mar 7 at 15:58
RoVoRoVo
3,442317
3,442317
add a comment |
add a comment |
Using read and awk:
read -r user domain < <(awk -F@ 'NR==1print $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
add a comment |
Using read and awk:
read -r user domain < <(awk -F@ 'NR==1print $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
add a comment |
Using read and awk:
read -r user domain < <(awk -F@ 'NR==1print $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
Using read and awk:
read -r user domain < <(awk -F@ 'NR==1print $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
answered Mar 7 at 16:55
Jesse_bJesse_b
14.3k33574
14.3k33574
add a comment |
add a comment |
g=`awk -F "@" 'NR==1print $1' filename `
y=`awk -F "@" 'NR==1print $NF' filename `
praveen@praveen:/tmp$ echo $g
49138
praveen@praveen:/tmp$ echo $y
bber0501u29b.bb2.cluster
add a comment |
g=`awk -F "@" 'NR==1print $1' filename `
y=`awk -F "@" 'NR==1print $NF' filename `
praveen@praveen:/tmp$ echo $g
49138
praveen@praveen:/tmp$ echo $y
bber0501u29b.bb2.cluster
add a comment |
g=`awk -F "@" 'NR==1print $1' filename `
y=`awk -F "@" 'NR==1print $NF' filename `
praveen@praveen:/tmp$ echo $g
49138
praveen@praveen:/tmp$ echo $y
bber0501u29b.bb2.cluster
g=`awk -F "@" 'NR==1print $1' filename `
y=`awk -F "@" 'NR==1print $NF' filename `
praveen@praveen:/tmp$ echo $g
49138
praveen@praveen:/tmp$ echo $y
bber0501u29b.bb2.cluster
answered Mar 10 at 13:20
Praveen Kumar BSPraveen Kumar BS
1,7391311
1,7391311
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f504948%2fextracting-text-from-a-file-when-i-know-its-format%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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