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.
RudiC
June 23, 2016, 5:30am
2
Please show your attempts!
RudiC
June 23, 2016, 6:15am
3
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
rdrtx1
June 23, 2016, 10:35am
4
awk '{a=$(NF - 3) FS $NF; print a}' RS="\n\n" infile
Aia
June 23, 2016, 8:26pm
5
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
rudic:
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
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 ----------
aia:
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 Aia,
I tried this and it worked can you please explain this inline perl command.
Thanks.
RudiC
June 24, 2016, 6:53am
7
How about: you "read" it to me and I tell you where you're right and where not...?
Aia
June 24, 2016, 10:14pm
8
Hi Aia,
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
I tried this and it worked can you please explain this inline perl command.
Thanks.
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