search directory-find files-append at end of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search directory-find files-append at end of line
# 1  
Old 03-02-2009
search directory-find files-append at end of line

Hi,

I have a command "get_data" with some parameters in few *.text files of a directory. I want to first find those files that contain this command and then append the following parameter to the end of the command.

example of an entry in the file :-

get_data -x -m50 /etc/web/getid

this should be changed to

get_data -x -m50 /etc/web/getid -ADD 31 -yxm

The value -ADD 31 -yxm should be repeated to all the files that contain this command

Thanks
# 2  
Old 03-02-2009
Bug

Try this :
Code:
$ list=$(find . -type f -exec grep -l "get_data " {} \;)
$ for i in $list
> do
> mv $i ${i}.old
> cat ${i}.old | sed 's/get_data.*/& -ADD 31 -yxm/' > $i
> done

Good luck ! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Append pipe | at the end of all the rows except header n trailer for all the files under a directory

Hi Experts Need help... I am looking for a Unix script to append pipe | at the end of all the rows (except header and trailer)in all the files placed under the directory /interfaces/Temp e.g. Header row1 row2 row3 Trailer The script should read all the files under... (3 Replies)
Discussion started by: phani333
3 Replies

2. Shell Programming and Scripting

Find keywords, and append at the end of line

Task: Find keywords in each line, and append at the end of line; if not found in the line, do nothing. the code is wrong. how to make it work. thanks a lot. cat keywords.txt | while read line; do awk -F"|" '{if (/$line/) {print $0"$line , ";} else print;}' outfile.txt > tmp ... (9 Replies)
Discussion started by: dtdt
9 Replies

3. UNIX for Advanced & Expert Users

Help in adding a string at the end of each line and append files vertically

hi, i need a help in the script , need to append a string at the end of each line of a files , and append the files into a single file vertically. eg file1 has the following columns abc,def,aaa aaa,aa,aaa files 2 has the following rows and columns abc,def,aaa aaa,aa,aaa i... (3 Replies)
Discussion started by: senkerth
3 Replies

4. Shell Programming and Scripting

sed - Find a String and append a text end of the Line

Hi, I have a File, which have multiple rows. Like below 123456 Test1 FNAME JRW#$% PB MO Approver XXXXXX. YYYY 123457 Test2 FNAME JRW#$% PB MO Super XXXXXX. YYYY 123458 Test3 FNAME JRW#$% PB MO Approver XXXXXX. YYYY I want to search a line which contains PB MO Approver and append... (2 Replies)
Discussion started by: java2006
2 Replies

5. Shell Programming and Scripting

Find command to search files in a directory excluding subdirectories

Hi Forum, I am using the below command to find files older than x days in a directory excluding subdirectories. From the previous forums I got to know that prune command helps us not to descend in subdirectories. Though I am using it here, not getting the desired result. cd $dir... (8 Replies)
Discussion started by: jhilmil
8 Replies

6. Shell Programming and Scripting

Search for a string, then append character to end of that line only

I have 2 files that I am working with $ cat file1 server1 server3 server5 server6 server8 $ cat file2 server1;Solaris; server2; SLES; server3;Linux; server4; Solaris; server5;SLES; server6;SLES; server7;Solaris; server8;Linux; (1 Reply)
Discussion started by: snoman1
1 Replies

7. Shell Programming and Scripting

Append variable texts to the beginning of each line in all files in a directory

I am writing a code to append some numbers in the beginning of each line in all the files present in a directory. The number of files are really huge. The files are numbered as 1.sco, 2.sco, 4.sco (Note: 3.sco is missing). The files currently look like this: 1.sco 2 3 5 6 6 7My task is to... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

8. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

9. Shell Programming and Scripting

Append text from one file to another based on a search from the end of a document

Hi all, I have output files that are all text files with various different extensions. So, if I submit the input file "job_name.inp", when it finishes I get an output file "job_name.dat". A typical input file looks something like this: $CONTRL SCFTYP=RHF RUNTYP=ENERGY MAXIT=199 MULT=1... (4 Replies)
Discussion started by: marcozd
4 Replies

10. Shell Programming and Scripting

How to append words at the end of first line

Hi Unix gurus This is my first post here. I have a file which looks like this: string1,string2 ,string3 ,string4 ... ... I need to append all words below first line to the first line, ie string1,string2,string3,string4,... Bear in mind that it is not known how many lines follow... (11 Replies)
Discussion started by: lmatlebyane
11 Replies
Login or Register to Ask a Question