Editing files to add some thing in all the files in a folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Editing files to add some thing in all the files in a folder
# 1  
Old 03-10-2010
Editing files to add some thing in all the files in a folder

Hi All,

I have a folder that contains 100's of files and each file have a similar content like the following format:
Code:
((STBJa:200.0,((STBTz:200.0,(STSwe:200.0,(STDUw:200.0,(ST4Bu:200.0,STL2b:200.0):127.0):86.0):80.0):120.0,
STAHr:200.0):134.0):200.0,STuNg:200.0);

What I need is to do is add "#1" after a specified word (say STAHr) in all the files in the folder. An example of the resulting file will be:

Code:
((STBJa:200.0,((STBTz:200.0,(STSwe:200.0,(STDUw:200.0,(ST4Bu:200.0,STL2b:200.0):127.0):86.0):80.0):120.0,
STAHr #1 :200.0):134.0):200.0,STuNg:200.0);

I need to specify the word (ex ST4BU) on the script and then add " #1 " (not that #1 is should have a space on both sides)

Please let me know the best way in awk or sed that could implement this in all the files in a folder. At one time I will only have to add #1 to only one word.

Please let me know.

LA
# 2  
Old 03-10-2010
Try:

Code:
var=STAHr
perl -i -ne 's/'$var'/'$var' #1 /g;print;' *

# 3  
Old 03-10-2010
Try this:

Code:
for file in *.txt
do
sed 's/STAHr/STAHr #1 /1' $file > /logs//file1.txt
mv /logs/file1.txt $file
done


Last edited by Scott; 03-10-2010 at 02:11 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move files with a certain suffix based on how many files are in another folder

Hello, First time poster. I am looking for a way to script or program the process of moving files from one folder to another, automatically, based on the count of files in the destination folder. I was thinking a shell script would work, but am open to the suggestions of the experts... (6 Replies)
Discussion started by: comtech
6 Replies

2. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

3. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

4. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

5. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

6. Shell Programming and Scripting

editing names of files in multiple folder

I have 1000's of directories which is named as numbers. Each directory contains multiple files. Each of these directories have a file named "att". I need to rename all the att files by adding the directory name followed by "_" then att for each of the directories. Directories 120 att... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

7. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

8. Shell Programming and Scripting

ksh shell script to add date (YYYYMMDDHHMISS) to all .txt files in a folder

Everyday 15 files are written to a folder \app\where\thefiles\are\destined\CURRFOLDER Task1: I need to add date in YYYYMMDDHHMISS format to each of them. Example: File: ACCOUNT.txt Should be updated as: ACCOUNT_20101005175059.txt Task 2: After I update the files, they need to be ... (2 Replies)
Discussion started by: Duminix
2 Replies

9. Shell Programming and Scripting

check how many files in folder or total files in folder

Hi all, I have copied all my files to one folder.and i want to check how many files (count) in the folder recently moved or total files in my folder? please send me the query asap. (3 Replies)
Discussion started by: durgaprasad
3 Replies

10. Shell Programming and Scripting

How list of files apart from *.class files in certain folder

Hi Friends How to list of all files in a particular directory structure, with out listing a particular file extn. I mean to say in a folder structure I have many files ..I want to list them with out *.class files. Please help Thanks Joy (3 Replies)
Discussion started by: itsjoy2u
3 Replies
Login or Register to Ask a Question