Replacing a string in a long list of files


 
Thread Tools Search this Thread
Operating Systems Solaris Replacing a string in a long list of files
# 1  
Old 01-10-2012
Replacing a string in a long list of files

I have a script that needs to read a file with a long list of /path/filenames - replace the name of the server in each file - and write the file to the same path with a date extension. This is the script that I have so far
Code:
#!/bin/ksh
umask 022
LIST=`scripts.list`
for i in $LIST
do
        sed "s/sourcestring/targetstring/g" "$i" > /tmp/temp.out
        mv /tmp/temp.out $i.0112
done

I keep getting an error that the sourcestring does not exist when testing - any help would be greatly appreciated!


Moderator's Comments:
Mod Comment Use code tags, see PM, thanks.

Last edited by zaxxon; 01-12-2012 at 11:42 AM.. Reason: code tags
# 2  
Old 01-10-2012
How does your input file look like ? please provide a sample.
Please also specify how look your server names or where they appear in your full_path/filename so we may then try to provide you an answer as accurate as possible.
# 3  
Old 01-10-2012
Example of a few lines of input file
Code:
/prod/feeds/intl/toyo/scripts/toyo_ftp.ksh
/prod/feeds/intl/twn/scripts/ftp.ksh
/prod/feeds/intl/twn/scripts/check_flag.ksh

I am replace the name of the server inside each file from '55ftp' to 'spftpc'

Last edited by zaxxon; 01-12-2012 at 11:42 AM.. Reason: as above
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help Moving Long List Of Files Into Directories

I am very new to BASH and I am having difficulties moving a long list of image files into similarly named directories. I've been trying to come with a script all night and no luck. Here is what my list of files looks like: DSC_0059_01.jpg DSC_0059_02.jpg DSC_0059_03.jpg DSC_0059_04.jpg... (5 Replies)
Discussion started by: jowens1138
5 Replies

2. Solaris

calculate sum size of files by date (arg list too long)

Hi, I wanted a script to find sum of files for a particular date, below is my script ls -lrt *.req | nawk '$6 == "Aug"' | nawk '$7 == "1"'| awk '{sum = sum + $5} END {print sum}' However, i get the error below /usr/bin/ls: arg list too long How do i fix that. Many thanks before. (2 Replies)
Discussion started by: beginningDBA
2 Replies

3. Shell Programming and Scripting

TAR Files Argument list too long error

Hi, I have a requirement where I need to TAR more than 50K files. Even though I can do TAR successfully on few 100s of files, but whenever Im trying to TAR the entire 50K files, I am getting the error message : Argument List Too Long. Please suggest how can i avoid this error. Im... (2 Replies)
Discussion started by: unx100
2 Replies

4. Shell Programming and Scripting

Replacing or removing a long list of pattern by using awk or sed

Input: >abc|123456|def|EXIT| >abc|203456|def|EXIT2| >abc|234056|def|EXIT3| >abc|340056|def|EXIT4| >abc|456000|def|EXIT5| . . . Output: def|EXIT| def|EXIT2| def|EXIT3| def|EXIT4| def|EXIT5| . . My try code: (9 Replies)
Discussion started by: patrick87
9 Replies

5. Shell Programming and Scripting

Replacing string in multiple files

Hi, I need to replace the string 'abcd' with 'xyz' in a file sample.xml This sample.xml is also present in the subdirectories of the current directory. Eg, If I am in /user/home/ the sample.xml if present in /user/home/ /user/home/folder1/ /user/home/folder2/... (3 Replies)
Discussion started by: arulanandsp
3 Replies

6. Shell Programming and Scripting

rm long list of files in a directory

Hi, I have used a command rm *.txt in a directory which has about 2000 txt files. but it is throwing the following error: error: args list too long. any ideas pls.. (16 Replies)
Discussion started by: techmoris
16 Replies

7. Shell Programming and Scripting

Replacing string in files

Hi, I Have 10 files ,I need replace $INPUT_LOCATION with $INPUT_LOCATION_upd .using sed command do it single file .How can change all files in single shot instead of doing individual file sed -s'/old/new/g' file1 Thanks, Mohan (2 Replies)
Discussion started by: mohan705
2 Replies

8. Shell Programming and Scripting

replacing a string in all files in a dir

Hello guys, I need help in globally replacing a string 'string1' with 'string2' in several files in a directory. In fact, also in all directories under it. Can anyone help me... Thanks (3 Replies)
Discussion started by: chiru_h
3 Replies

9. UNIX for Dummies Questions & Answers

arg list too long when trying to tar files

Hi, I am trying to perform this task: tar -cvf tar.newfile ??????.bas I got error "arg list too long". Is ther any way around? I have about 1500 file need to be tar together. Thanks in advance (5 Replies)
Discussion started by: jds3
5 Replies

10. UNIX for Dummies Questions & Answers

arg list too long when mv files?

hello all i need some help because i am a unix/linux dummy...i have the following: DIR1> has 121437 files in it with varying dates going back to early April, a sub dir DIR1/DIR2> has 55835 files in it I need to move all files (T*.*) out of DIR1 into DIR2 that are older than today? Ive been... (2 Replies)
Discussion started by: jamos007
2 Replies
Login or Register to Ask a Question