search and insert

search and insert

Postby Skaperen » Thu Aug 18, 2016 5:39 am

i had a need for this today and ended up using a rather awkward solution. i think it could be done better with a relatively small python script. the command takes two strings and one or more files. search for the string in each file and insert the 2nd string after the found line in each file.

extras:

1. if '-r' or '-e' option given, do the search with the 1st string being a regexp ... or use -f to mean not a regexp.

2. preserve date, group and permissions. if run as root, also preserve ownership.

3. other features you think are useful.
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016. This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
Skaperen
 
Posts: 267
Joined: Tue Apr 07, 2015 9:58 am
Location: Wheeling WV USA

Re: search and insert

Postby micseydel » Thu Aug 18, 2016 6:05 am

Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to Challenges

Who is online

Users browsing this forum: No registered users and 1 guest