file operations in shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file operations in shell scripting
# 1  
Old 12-30-2008
file operations in shell scripting

hi All,

my query...
1.I Have to search for the files in the root directory.
2.i have to search for a pattern in all the files in the root directory and then replace them with a new pattern.
3.Rename the file

Explanation:
if ABC is the root folder and has 3 subfolders and there are 15 files in total. i am searching for the string December and then i have to change it to January and rename the file which has the desired pattern(e.g December)

i am working on sunos 5.8 and i tried with the sed command but the -i option is not supported.
Please give me some suggestions...
# 2  
Old 12-30-2008
post what you have done....
# 3  
Old 12-30-2008
i am actually waiting for a solution from some gurus ..
i shall update once i am done
# 4  
Old 12-30-2008
u can use the following way..this is part of suggestion and you can carry it from next sequence onward

find / -type f -name <pattern of file> -exec sed 's/search text/replaced text/g' {} \;

this will search the particular pattern of files from root, then search the <search text>and replace the same with <replaced text>

then loop the above one and rename the same .
best of luck..Smilie
# 5  
Old 12-30-2008
hi manas ,

wht should i give in place of <file pattern>
I am using sed "s/as/AS/g" $file >> $newfile
but the string 'as' is replaced by 'AS' in all the places. i need to replace it only for the 'as' word but not the string

e.g
file has the contents:
manas
as far as you go
has

output should be:
manas
AS far AS you go
has

but not
manAS
AS far AS you go
hAS

some suggestions pls
# 6  
Old 12-30-2008
If you just want the word, put spaces around it.

"s/ as / AS /g"
Padow
# 7  
Old 12-31-2008
if i want to replace "mahi" and "MAHI" with "MAHI_123" then how can i do it without two sed cmds how do i do it?

this is wht i did

sed "s/ mahi / MAHI_123 /g" $file >> $F1

cp $F1 $F1.orig
sed -e "s/ MAHI / MAHI_123 /g" $F1.orig > $F1
rm $F1.orig

can anyone please suggest anything better than this
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell operations from C++

Hi everyone, I need little help in shell operations from C++ program. Here I furnish the details of problem: 1. Lets say my current working path is myWorkingPath. 2. In my working path I have list of name directories and each name directory has two more sub directories say A/B. (now path to... (5 Replies)
Discussion started by: linuxUser_
5 Replies

2. Shell Programming and Scripting

To skip operations in UNIX shell

hi i am having a acript for which i need to skip the execution of some lines and to continue with remaining lines for eg script.sh rm text for i in * do . . . . . if then rm i want to skip the execution of the lines and to start with (11 Replies)
Discussion started by: rohit_shinez
11 Replies

3. Shell Programming and Scripting

Shell arithmetic : operations on decimal points

i am having a varialbe a , which is input to my file i want to multiply this input with value .43, and assign it to variable b. i tried it as below: #!/bin/sh a=$1 b=`expr $1\*0.43` echo b=$b error : expr: non-integer argument Please tell me , how to do this. Thanks (10 Replies)
Discussion started by: rishifrnds
10 Replies

4. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

5. Shell Programming and Scripting

How to search and append words in the same file using unix scripting file operations

Hi , I have a file myhost.txt which contains below, 127.0.0.1 localhost 1.17.1.5 atrpx958 11.17.10.11 atrpx958zone nsybhost I need to append words only after "atrpx958" like 'myhost' and 'libhost' and not after atrpx958zone. How to search the word atrpx958(which is hostname) only,... (5 Replies)
Discussion started by: gsreeni
5 Replies

6. Programming

shell cursor operations

Hi I need to save the actual cursor position into variable in my script. How can I do it ? thx for help. (1 Reply)
Discussion started by: presul
1 Replies

7. Programming

shell scripting problems involving operations with remote machine

Hi, i have been developing a shell script to transfer a set of files from one ubuntu system to another. Task: while executing the script the files ( ls, dir, cat) in the source machine should transfer to destination machine(at /home/mac/mac/bin) While the script is executed once again, It... (0 Replies)
Discussion started by: srijith
0 Replies

8. Shell Programming and Scripting

Help on shell script (string operations)

Hey everyone. So the background of the problem is that the ps3 does not support the mkv container, but DOES support the avi one. Here is the script to convert one file with the name hardcoded in: #!/bin/sh mencoder -oac... (2 Replies)
Discussion started by: wua05
2 Replies

9. Shell Programming and Scripting

Unix file operations(shell script)

Hi, I want to compare two files. Files will look like as follows: file1: ASDFGHJU|1234567890123456 QWERTYUI|3456789098900890 file2: ZXCVBVNM|0987654321234567 POLKIJUYH|1234789060985478 output file should be: ASDFGHJU|1234567890123456 QWERTYUI|3456789098900890 Thnaks in advance (6 Replies)
Discussion started by: nivas
6 Replies
Login or Register to Ask a Question