Adding lines to each block in a multicolumn text file
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My New Line My New Line My New Line
g51/b18468 Postgg On 30/05/2013 N51/b39897 Postgg On 30/05/2013 LR51/b23428 Postgg On 30/05/2013
Rgv. XXXXX Mr. bBnMbNNbN.M Bro. bBRbgbM .S,
KbgbNg bSSgMBLY Og gOg, LOT 92, KbMPUNg gRbgg gOMMUNnTY ggNTRg,
52, gLN. TnMUR, BbTU 4, 43950 4, LORONg SS 23/6g,
POST BOX 20, 43007 KbgbNg SUNgbn PgLnK 47400 PgTbLnNg gbYb,
MbLbYSnb SgLbNgUR SgLbNgOR, W.MbLbYSnb
MbLbYSnb MbLbYSnb
for all addresses ofc while maintaining same formatting. I dont know how to achieve this. Can you guys help me out with this?
In which word processor or programming language are you planning to accomplish this? What have you tried so far?
If every address field has the same height and width, including the blank padding below and to the right of each address, you don't even have to do anything sophisticated like searching for patterns. You could just write a word processor script (or macro) to repeatedly count lines and insert the new text. The new text would not be
By the way, I have suggested a way to handle this as a one-time problem. If you plan to maintain this address list and modify it in the future, you really should rearrange it into one column or some other structure or database that will make your future work easier.
The input and output separators have been set to three contiguous newlines, and each record is simply prepended with the desired string and then printed. I used variables for the string and padding spaces just to compact things a bit.
It could probably be done somewhat cleaner with printf instead, but this works well enough.
Finally, I agree with Beryllos. Lists of database-style entries are easier to manipulate if each record is kept separate.
stevanity, It appears that your sample text is a substitution cipher. Before we all have some fun cracking it, I need to ask you if it is important for reasons of privacy or security to keep the names and addresses secret. If so, you should delete them.
Can you please explain, what did you exactly do to achieve this using awk?
I have understood
Quote:
str="My New Line" ; sp=" " }
both are equal to 37 characters, exact space between two addresses but I could not understand $0. what does it do?
As well as I could not understand the functionality of RS=ORS="\n\n\n"; & "\n" $0 ;
Can you please explain this?
Thanks !!!
Last edited by unclesamcrazy; 06-05-2013 at 04:44 AM.
Well, a full explanation really requires understanding something of how awk works. Check out the links below.
But in brief, awk divides the input into records, and then further subdivides the records into fields. By default a record is a line, and a field is a word, but this can be changed. RS is the input record separator variable, which I set to match three consecutive newlines. ORS is the output record separator, which needs to be set to the same as the input if you want to keep the same formatting.
$0 refers to the current record as a whole. So the command just re-sets it to be equal to the new line plus itself, then prints it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.