Change lines in multiple files

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Change lines in multiple files
# 1  
Old 07-12-2011
Change lines in multiple files


I have a folder with a large number of files and would like to apply the following changes to each line in each of the files:

sed 's/$/\/Q:_0/'

I wrote a loop, but it just changes the name of the file, not the contents of the file:
for i in ./dir/*.lab 
    sed 's/$/\/Q:_0/'

Can someone help please?
# 2  
Old 07-12-2011
for i in ./dir/*.lab 
    sed 's/$/\/Q:_0/' $i > tmp.tmp
    mv tmp.tmp $i

This User Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

2. Shell Programming and Scripting

Change name of multiple files

Hi Guys Please can you help me. I have a lot of files whit wrong name example 00000500_001.segd 00000501_001.segd 00000502_001.segd 00000503_001.segd 00000504_001.segd I would like to remove _001 in all files So, the files shouldbe 00000500.segd 00000501.segd 00000502.segd... (2 Replies)
Discussion started by: jiam912
2 Replies

3. UNIX for Dummies Questions & Answers

Want to change common line from multiple files

Hi everyone, I've a requirement to modify an existing line which is common to multiple files. I need to replace that existing line with a new line. I've almost 900 ksh files to edit in the similar fashion in the same directory. Example: Existing Line: . $HOME/.eff.env (notice the "." at the... (3 Replies)
Discussion started by: kaleem.adil
3 Replies

4. Shell Programming and Scripting

Count lines from multiple files (3)

Hey everyone, I've to count lines from string of files names then to show sum output of lines. for example: read x = F1 F2 F3 F1 = 12 lines F2 = 14 lines F3 = 10 lines = 36 what I did is: read x echo $x >|temp for x in $(cat temp) do wc -l < $x (3 Replies)
Discussion started by: Aviv
3 Replies

5. Shell Programming and Scripting

read the lines of multiple files

I am trying to create a script which will read 2 files and use the lines of file 1 for each line on file 2. here's my sample code cat $SBox | while read line do cat $Date | while read line do $SCRIPTEXE <line from first file> $2 <line from 2nd file> ... (12 Replies)
Discussion started by: khestoi
12 Replies

6. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

7. Shell Programming and Scripting

grep from multiple lines in several gz files

Hello all, I have been struggling to get grep work to my requirements. Basically I have to filter out patterns spread across multiple lines over hundreds of .gz files in a folder. And the output needs to be piped to a file. Here is the example: folder name: logs files in this folder:... (4 Replies)
Discussion started by: mandhan
4 Replies

8. UNIX for Dummies Questions & Answers

change name of multiple files in a same folder

I searched and tried many answers from similar questions on this forum, but none of them finished my job. Maybe I am too novice to unix. Sorry I have to ask again,and hope I can get the answer. I have a folder with files sqcu001v.jpg, sqcu002v.jpg, ... sqcu100v.jpg. I want to have... (3 Replies)
Discussion started by: softmud
3 Replies

9. Shell Programming and Scripting

replace multiple lines in multiple files

i have to search a string and replace with multiple lines. example Input echo 'sample text' echo 'college days' output echo 'sample text' echo 'information on students' echo 'emp number' echo 'holidays' i have to search a word college and replace the multiple lines i have... (1 Reply)
Discussion started by: unihp1
1 Replies

10. Shell Programming and Scripting

Adding Multiple Lines to Multiple Files

Hello, I have three lines I need to add to hundreds of files. The files are all in the same format and contain the same information. I want to add the same information to the files. The new lines of information are similar. Here is an example of the three lines: line1: line2 =... (2 Replies)
Discussion started by: dayinthelife
2 Replies
Login or Register to Ask a Question