Switch line in txt file

Hi

I have problem with replace line in txt file , I have this string:

144185 DISK
Piece  qqr8ot6l_1_1

--
144186 DISK
Piece  ukr8pf2e_1_1

--
144187 DISK
Piece  ter8p9gc_1_1

--
144188 DISK
Piece  4er8qb84_1_1

and
I need to do :

144185 qqr8ot6l_1_1
144186 ukr8pf2e_1_1
144187 ter8p9gc_1_1
144188 4er8qb84_1_1

I tried combination awk and grep but any results.

Please show your attempts!

Howsoever, would this do:

awk '$NF == "DISK" {$NF = ""; X = $0; getline; $1 = ""; $0 = X $0; print}' file
144185  qqr8ot6l_1_1
144186  ukr8pf2e_1_1
144187  ter8p9gc_1_1
144188  4er8qb84_1_1
1 Like
awk '{a=$(NF - 3) FS $NF; print a}' RS="\n\n" infile
perl -nle '$p and print "$p ",(split)[1]; ($p)=/^(\d+)/' primo102.file

Output:

144185 qqr8ot6l_1_1
144186 ukr8pf2e_1_1
144187 ter8p9gc_1_1
144188 4er8qb84_1_1

Hi RudiC,

I tried this and it worked can you please explain this command.

Thanks.

---------- Post updated at 04:20 PM ---------- Previous update was at 04:19 PM ----------

Hi Aia,

I tried this and it worked can you please explain this inline perl command.

Thanks.

How about: you "read" it to me and I tell you where you're right and where not...?

It is based on the premise that the following structure is true:
A line starting with a digit or more which we want to capture, followed by another line where we would like to split the line into two, using an space as separator.
You should then read the command starting from its end.

($p)=/^(\d+)/     # capture the digits in the beginning of the line
$p and print      # if there were digits captured, print the following:
"$p ",(split)[1]; # the previous obtained number and the second part of splitting the current string in half, adding an space in between
1 Like

Thank you