Insert a newline after match in files of specific name under some subdirectories?
Hi
I'd like to add the newline:
\tuser: nobody", or "<TAB>user: nobody
to all files named:
in subfolders of pwd with names beginning with 10-20.
Within these files, I'd like to find the line (there'll only be one) containing:
NOTE: As far as I know, each of these lines will actually contain: command: celery worker -l info -A snakeeyes.blueprints.contact.tasks, but I haven't checked each file, some may differ so the above search pattern seemed reasonable.
And append on a new line directly below the matching line, the aforementioned string, either:
\tuser: nobody", or "<TAB>user: nobody
If anyone knows how to do this, a (if possible, verbosely annotated) answer would be greatly appreciated!
---
Not Important:
I've been trying to figure this out by myself - I had been reading Sed & Awk by Dougherty & Robbins earlier this year, but I haven't gotten very far, and there's nothing in my notes for this sort of case... here's what I had come up with thus far after searching line and combining different things I read:
Mostly including this not as a starting point, but so you can laugh at it (it mangled the files)
Moderator's Comments:
Please use CODE tags as required by forum rules!
Last edited by duncanbetts; 11-01-2016 at 01:25 PM..
Reason: Added CODE tags.
I have a sample directory structire like following
# pwd
/user/test
and I have files like following
out.txt
A/a.txt
B/b.txt
C/c.txt
(A,B,C are directories )
# tar cvf test.tar *
a A/a.txt 1 blocks
a B/b.txt 1 blocks
a C/c.txt 1 blocks
a out.txt 1 blocks
But whenever I give (4 Replies)
I have successfully used regexp and sed to insert a newline before or after a line containing a matched pattern /WORD/. However, I want to insert a newline immediately following /WORD/ and not after the -line- containing the pattern matched. I can match a pattern, but it is matched via a wild card... (2 Replies)
Hi,
I need to insert two newline characters after matching of a pattern in each line of a file.
Eg. If i have a file with contents as follows:-
Now, i want output as follows :-
i.e., I need to insert two newline characters after the occurance of pattern "</Message>>".
Thnx... (1 Reply)
Hi ,
I am having an issue with the Awk script to insert newline for a regular expression match
Having a file like this
FILE1
####################
RXOER , RXERA , RXERC , RXERD
.RXEA(RXBSN), RXERD , REXCD
input RXEGT
buffer RXETRY
#######################
Want to match the RXE... (38 Replies)
Hi all,
I have been searching online to find the answer for getting a list of files that do not match certain criteria but have been unsuccessful.
I have a directory that has many jpg files. What I need to do is get a list of the files that do not match both of the following patterns (I have... (21 Replies)
Hi,
I use sed to insert text at beginning of a file. But sed inserts a newline after my text that I do not need. For example, I want to insert "foo" at the beginning of my file:
> cat myfile
This is first line.
> sed -i '1i\foo' myfile
> cat myfile
foo
This is first line.
... (5 Replies)
Hi all,
I'm new to this forum and bash scripting. I have the following problem, I need to copy some files (from one dir. to another) whose first 5 numbers (subjects' ID) match the directory names. Here a shortened version of what I'm trying to do:
names=(32983_f 35416_f 43579_f) # these are... (6 Replies)
Given a csv file with 40 columns with name, address, hometown etc.
I use a bash command in 1 line which:
1. gets the address column and pipes that to
2. grep the first digit and everything that follows
Command:
awk -F ";" '{print $19}' /Users/jb/Desktop/ReorderTempTotal.csv | grep -o "\d.*"... (7 Replies)
I am trying to mv each of the .vcf files in the variants folder to the folder in /home/cmccabe/f2 that the .vcf id is found in file. $2 in file will always have the id of a .vcf in the variants folder. The line in blue staring with R_2019 in file up to the -v5.6 will always be an exact match to a... (4 Replies)