I have a file that contains the following:
^field LINE_1 data
^field LINE_2 data
^field LINE_3 data
^field LINE_4 data
^field LINE_5 data
...
And im looking to do a line break at the end of the number before the text to make it look like this
^field LINE_1
data
^field LINE_2
data
^field LINE_3
data
^field LINE_4
data
^field LINE_5
data
I have been unsuccesfully searching all day, any help woudl be great
Thanks
You can try below
awk '{print $1" "$2"\n"$3}' input_file > output_file
Regards,
Vishal
Thank you vishalaswani
that is 99% there!
It chopps it off at the first word after the break, if i have a line with 20 words on it, how do i make it read to the end?
zaxxon
October 25, 2011, 9:34am
4
Should it always put the last word in the next line, no matter how many words there are?
Yes
If the line was to say "THIS IS ALL YOUR TEXT" i would need it to have all of it and not just the first word
zaxxon
October 25, 2011, 9:38am
6
I do not understand that explanation, but you can try this:
awk '{$NF=RS $NF; print}' infile
In case that is not what you are looking for, post your complete example input and an example output using
```text
and
```
tags, thanks.
Sorry for the confusion, if i was to have this:
^field LINE_22
^field LINE_23 BILLING CREDIT AVAILABLE PAST DUE MINIMUM TOTAL DUE
^field LINE_24 DATE LIMIT CREDIT PAYMENT
^field LINE_25 00-00-00 0 0 .00 .00 .00
^field LINE_26 00-00-00 0 0 .00 .00 .00
i would like the final output to be:
^field LINE_22
^field LINE_23
BILLING CREDIT AVAILABLE PAST DUE MINIMUM TOTAL DUE
^field LINE_24
DATE LIMIT CREDIT PAYMENT
^field LINE_25
00-00-00 0 0 .00 .00 .00
^field LINE_26
00-00-00 0 0 .00 .00 .00
Does that help?
zaxxon
October 25, 2011, 9:42am
8
Maybe I understood it after reading again:
$> cat infile
^field LINE_1 This is all your text A
^field LINE_2 This is all your text B
^field LINE_3 This is all your text C
$> awk '{$3=RS $3; print}' infile
^field LINE_1
This is all your text A
^field LINE_2
This is all your text B
^field LINE_3
This is all your text C
zaxxon
October 25, 2011, 9:45am
9
Just saw the example:
$> awk '{$3=RS "\t"$3; print}' infile
^field LINE_22
^field LINE_23
BILLING CREDIT AVAILABLE PAST DUE MINIMUM TOTAL DUE
^field LINE_24
DATE LIMIT CREDIT PAYMENT
^field LINE_25
00-00-00 0 0 .00 .00 .00
^field LINE_26
00-00-00 0 0 .00 .00 .00
Awesome! My only dilema with that is its losing its white space before and in between words, any suggestions?
CarloM
October 25, 2011, 10:23am
11
Can't you just do:
sed 's/LINE_[0-9][0-9]*/&\n/'
a bit ugly, but....
nawk '{match($0,"^[^"FS"]+"FS"+[^"FS"]+");print substr($0,1,RLENGTH) RS substr($0,RSTART+RLENGTH)}' myFile