Skip to main content
Added formatting and rephrased question to make it more accessible.
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Use awk print $4 to beginingprepend the line with a specific field of the line

using awk imUsing awk, I'm trying to print $4 to the fourth field of an input line ($4) also at the begining of the line the.

I have tried the following code below prints, but it aboveprints the line the string is random so cant use string nameabove the line:

awk -F"[--]" '{print $4 ;print$0}' file 

i haveThe string is random so I can't use the string name.

The input like looks as follows:

/example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

withWith the code above iI get:

320 /example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

neededI need the output to look like:

320/example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

thanksThanks for help!

awk print $4 to begining of the line

using awk im trying to print $4 to the the begining of the line the code below prints it above the line the string is random so cant use string name

awk -F"[--]" '{print $4 ;print$0}' file 

i have

/example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

with code above i get

320 /example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

needed

320/example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

thanks for help

Use awk to prepend the line with a specific field of the line

Using awk, I'm trying to print the fourth field of an input line ($4) also at the begining of the line.

I have tried the following code, but it prints the string above the line:

awk -F"[--]" '{print $4 ;print$0}' file 

The string is random so I can't use the string name.

The input like looks as follows:

/example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

With the code above I get:

320 /example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

I need the output to look like:

320/example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

Thanks for help!

Source Link
bob
  • 45
  • 3

awk print $4 to begining of the line

using awk im trying to print $4 to the the begining of the line the code below prints it above the line the string is random so cant use string name

awk -F"[--]" '{print $4 ;print$0}' file 

i have

/example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

with code above i get

320 /example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

needed

320/example-origin-live/ngrp:tennis-320-fd1d9b92-69e2-446c-a3e6-45b33a55efc9 

thanks for help