Search the file with some content and insert the row after that and write some other thing - text-editor

I want to edit the file in the following way
My Sample File:
101 273970116 2719674681506161941D094101METABANK WAVECREST
5220Taxi Charger Micro Deposit - Cr A271967468WEBP2P 150616 1273970110000001
6220110000156534057672 0000000007GreenGrP2C386daTest User S 0273970110000001
6220110000156534057672 0000000005ClarkGrP2C386dcTest User S 0273970110000002
82200000020002200002000000000000000000000012A271967468 273970110000001
9000001000001000000020002200002000000000000000000000012
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
In the above file, wherever if i find the row starting with number '6' , i need to insert the line after that row and write some thing as
ex : 798R03073972187779351 05190376011000015 044000024265158
Finally my output file should be as below:
101 273970116 2719674681506161941D094101METABANK WAVECREST
5220Taxi Charger Micro Deposit - Cr A271967468WEBP2P 150616 1273970110000001
6220110000156534057672 0000000007ClarkGrP2C386daTest User S 0273970110000001
798R03073972187779351 05190376011000015 044000024265158
6220110000156534057672 0000000005ClarkGrP2C386dcTest User S 0273970110000002
798R03073972187779351 05190376011000015 044000024265158
82200000020002200002000000000000000000000012A271967468 273970110000001
9000001000001000000020002200002000000000000000000000012
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
Can someone please help me to get the solution for this. ?
Regards,
Saidivya

Related

Rad a particular line from a string and then delete the rest in nodejs

I have a string which is like
name : Rahul
surname : Chopra
school : KVMPSS
I need to read the first line , thats the name : Rahul then delete the rest. How can I do it. I am new to nodejs. Please help
Do this to get the first line of your file:
your_string = "hi\nhello\nhello\nworld";
line_1 = your_string.split(/\r?\n/)[0];
console.log(line_1)
This is not efficient for large files, but it's fine for smaller ones.

Parsing text in dictionary

I have a dictionary which has following text:
{
"body": "Customer: \"I have a big problem. You cut off my head!\"\r\n\r\nMe: \"I'm sorry? How did I cut off your head?\"\r\n\r\n(The customer shows me an obviously self-taken picture, with the top of his head removed.)\r\n\r\nMe: \"Sir, it looks like it was taken that way.\"\r\n\r\nCustomer: \"No it wasn't! My whole head was there when I took it. I'm sure!\"\r\n\r\nMe: \"Okay, let me see your memory card...\"\r\n\r\n(The customer hands it to me, and I go in the lab and pull it up on the computer. Sure enough, he chopped his own head off in the picture.)\r\n\r\nMe: \"Sir, that is the whole image, and the top of your head isn't in it.\"\r\n\r\nCustomer: \"But it's DIGITAL, can't you fix it?\"\r\n\r\nMe: \"You can't create something from nothing.\"\r\n\r\nCustomer: \"But... but... but... I need a photo for a dating website!\"\r\n\r\nMe: \"Give me the camera and go stand over there.\"\r\n\r\nCustomer: *excited* \"Hot d***! You can be my best man!\"\r\n\r\nMe: \"A thank you card will be enough.\"\r\n\r\n(Skip ahead 9 months...)\r\n\r\nFemale customer: \"Is your name ***?\"\r\n\r\nMe: \"Yes, can I help you?\"\r\n\r\nFemale customer: \"My husband wanted you to have this.\" *hands me an envelope*\r\n\r\n(I open the envelope, and sure enough there's a thank you card with a picture of him and his wife. He actually got married and sent her in with the card!)",
"category": "Men / Women",
"id": 18189,
"title": "A Heady Proposition"
},
But I am not sure at all how to parse the text for body so that I can get a readable text from above.
I am looking for a general solution instead of parsing based on keywords like Customer and Me
The text should look as following image:
You can split by the delimiter pattern \r\n\r\n+
Using the re and pprint modules:
pprint(re.split('\r\n\r\n+',your_dict['base']))
generates:
['Customer: "I have a big problem. You cut off my head!"',
'Me: "I\'m sorry? How did I cut off your head?"',
'(The customer shows me an obviously self-taken picture, with the top of his '
'head removed.)',
'Me: "Sir, it looks like it was taken that way."',
'Customer: "No it wasn\'t! My whole head was there when I took it. I\'m '
'sure!"',
'Me: "Okay, let me see your memory card..."',
'(The customer hands it to me, and I go in the lab and pull it up on the '
'computer. Sure enough, he chopped his own head off in the picture.)',
'Me: "Sir, that is the whole image, and the top of your head isn\'t in it."',
'Customer: "But it\'s DIGITAL, can\'t you fix it?"',
'Me: "You can\'t create something from nothing."',
'Customer: "But... but... but... I need a photo for a dating website!"',
'Me: "Give me the camera and go stand over there."',
'Customer: *excited* "Hot d***! You can be my best man!"',
'Me: "A thank you card will be enough."',
'(Skip ahead 9 months...)',
'Female customer: "Is your name ***?"',
'Me: "Yes, can I help you?"',
'Female customer: "My husband wanted you to have this." *hands me an '
'envelope*',
"(I open the envelope, and sure enough there's a thank you card with a "
'picture of him and his wife. He actually got married and sent her in with '
'the card!)']
You can now print this array line by line to a PDF using the module pyPdf, with a nice font of your choice - achieving the look above +-.
You'll need to add further code to add some formatting, such as the italics above; e.g.:
Anything before a : should be bolded, and any line holding )( should be italicized.

How to sort data of a file in python(windows)

We are trying to implement a file based student record program.We want to sort the file that contain the details of the student according to the roll number which is at the first position of every line.
the file contains the following data:
1/rahul/cs
10/manish sharma/mba
5/jhon/ms
2/ram/bba
We want to sort the file's data according to the first field i.e. roll number.
Any help shall be great
You use sorted:
dataSorted = list(sorted(f.readlines()))
If you want to sort only the first element use:
dataSorted = list(sorted(f.readlines(), lambda line: line[:line.find('/')]))
f is the file-object.
Further information: help(sorted)

Position cursor when asking a user for input in Vim?

I'm writing a custom function in Vim which asks the user what they would like to rename the current file to:
let b:newname = input('Rename to: ', expand('%'))
It prepopulates the input field with the filename such as ExampleFile.php. However I would like to position the cursor just before the . as more often than not, users will be renaming the file as opposed to the extension.
However, I cannot figure out a way to move the cursor. Even <Left><Left><Left> would suffice if I could get it to work
You can insert special keys in a double quote string with \<xxx>. Check the help for expr-quote. So just concatenate that to your string:
let b:newname = input('Rename to: ', expand('%') . "\<left>\<left>\<left>\<left>")

Adding extra characters to a list of email adresses in tsql

I have an output text file with millions of email addresses in them. I need an sql function to take each each email address as input and format it to add the ' and ', characters to them. So as an example:
Input is:
joe.bloggs#test.com
dan.bloggs#test.com
Expected Output:
'joe.bloggs#test.com',
'dan.bloggs#test.com',
select ''''+replace('joe.bloggs#test.com dan.bloggs#test.com', ' ', ''', ''')+''''
So to answer one of my junior devs under my login - a quick solution:
SELECT distinct(',''' + Email + '''')
FROM [Table]

Resources