print value from first line on each line
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I have file of following format:
1.0
2.0
3.0
4.0
5.0
Is it possible to copy value in first line 1.0
to the beginning of every line in awk? Like this:
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
text-processing awk
add a comment |Â
up vote
5
down vote
favorite
I have file of following format:
1.0
2.0
3.0
4.0
5.0
Is it possible to copy value in first line 1.0
to the beginning of every line in awk? Like this:
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
text-processing awk
With GNU sed:sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file
In this case,awk
is more transparent.
â Cyrus
Dec 25 '17 at 11:31
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I have file of following format:
1.0
2.0
3.0
4.0
5.0
Is it possible to copy value in first line 1.0
to the beginning of every line in awk? Like this:
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
text-processing awk
I have file of following format:
1.0
2.0
3.0
4.0
5.0
Is it possible to copy value in first line 1.0
to the beginning of every line in awk? Like this:
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
text-processing awk
edited Dec 25 '17 at 11:21
Jeff Schaller
31.8k848109
31.8k848109
asked Dec 25 '17 at 7:43
Bhavin Chirag
1514
1514
With GNU sed:sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file
In this case,awk
is more transparent.
â Cyrus
Dec 25 '17 at 11:31
add a comment |Â
With GNU sed:sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file
In this case,awk
is more transparent.
â Cyrus
Dec 25 '17 at 11:31
With GNU sed:
sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file
In this case, awk
is more transparent.â Cyrus
Dec 25 '17 at 11:31
With GNU sed:
sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file
In this case, awk
is more transparent.â Cyrus
Dec 25 '17 at 11:31
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
8
down vote
accepted
awk 'NR==1 f=$1 print f,$1' file
Output:
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
If current line number (NR
) is 1 then save column 1 ($1
) to variable f
. For every line print content of variable f
and content of column 1.
i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
â Ã±ÃÂñýàñüÃÂÃÂùcñ÷
Dec 25 '17 at 7:56
add a comment |Â
up vote
1
down vote
I have done this by sed command working as expected
k=`sed -n 1p file`;sed "s/^/$k /g" file
output
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
awk 'NR==1 f=$1 print f,$1' file
Output:
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
If current line number (NR
) is 1 then save column 1 ($1
) to variable f
. For every line print content of variable f
and content of column 1.
i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
â Ã±ÃÂñýàñüÃÂÃÂùcñ÷
Dec 25 '17 at 7:56
add a comment |Â
up vote
8
down vote
accepted
awk 'NR==1 f=$1 print f,$1' file
Output:
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
If current line number (NR
) is 1 then save column 1 ($1
) to variable f
. For every line print content of variable f
and content of column 1.
i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
â Ã±ÃÂñýàñüÃÂÃÂùcñ÷
Dec 25 '17 at 7:56
add a comment |Â
up vote
8
down vote
accepted
up vote
8
down vote
accepted
awk 'NR==1 f=$1 print f,$1' file
Output:
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
If current line number (NR
) is 1 then save column 1 ($1
) to variable f
. For every line print content of variable f
and content of column 1.
awk 'NR==1 f=$1 print f,$1' file
Output:
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
If current line number (NR
) is 1 then save column 1 ($1
) to variable f
. For every line print content of variable f
and content of column 1.
edited Dec 25 '17 at 9:00
answered Dec 25 '17 at 7:55
Cyrus
7,0362835
7,0362835
i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
â Ã±ÃÂñýàñüÃÂÃÂùcñ÷
Dec 25 '17 at 7:56
add a comment |Â
i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
â Ã±ÃÂñýàñüÃÂÃÂùcñ÷
Dec 25 '17 at 7:56
i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
â Ã±ÃÂñýàñüÃÂÃÂùcñ÷
Dec 25 '17 at 7:56
i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
â Ã±ÃÂñýàñüÃÂÃÂùcñ÷
Dec 25 '17 at 7:56
add a comment |Â
up vote
1
down vote
I have done this by sed command working as expected
k=`sed -n 1p file`;sed "s/^/$k /g" file
output
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
add a comment |Â
up vote
1
down vote
I have done this by sed command working as expected
k=`sed -n 1p file`;sed "s/^/$k /g" file
output
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
add a comment |Â
up vote
1
down vote
up vote
1
down vote
I have done this by sed command working as expected
k=`sed -n 1p file`;sed "s/^/$k /g" file
output
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
I have done this by sed command working as expected
k=`sed -n 1p file`;sed "s/^/$k /g" file
output
1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0
answered Dec 25 '17 at 9:28
Praveen Kumar BS
1,010128
1,010128
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412906%2fprint-value-from-first-line-on-each-line%23new-answer', 'question_page');
);
Post as a guest
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
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
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
With GNU sed:
sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file
In this case,awk
is more transparent.â Cyrus
Dec 25 '17 at 11:31