Find / sed on lnx/AIX/sun


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find / sed on lnx/AIX/sun
# 1  
Old 06-11-2013
Find / sed on lnx/AIX/sun

Hello @all

first of all in the best case this script has to work on every os (lnx/aix/sun).

It's very simple what it should do.

I have a standard path and I'll call it for this example /myhome/scripts
Within this path there are more files and folders and some of them are tagged with "orig_*" or "*_orig" at the beginning or at the end.

Code:
directory (e.g)
/myhome/scripts/orig_runscript.sh
/myhome/scripts/etc/orig_daemon_cfg.cfg
/myhome/scripts/etc/multi/multi_orig.cfg
/myhome/scripts/orig_perl64/files/files1.file

Code:
/myhome/scripts/runscript.sh
/myhome/scripts/etc/daemon_cfg.cfg
/myhome/scripts/etc/multi/multi.cfg
/myhome/scripts/perl64/files/files1.file


I want to find all of these files/folders and want to rename all of them but without the orig.

What i come around with.

Code:
MY_HOME="/myhome/scripts"
FIND_ORIG="$MY_HOME/find_orig.out"

echo "rename all orig_ files"
find ${MY_HOME}/orig_* >> ${FIND_ORIG} 2>/dev/null
for LINE in `cat ${FIND_ORIG}`; do
	OLD_NAME=${LINE}
	NEW_NAME=${LINE} | sed -e 's/orig_//'
	mv ${OLD_NAME} ${NEW_NAME} >> ${INSTALL_LOG}
        echo "moved $OLD_NAME to $NEW_NAME"
done
echo "done with renaming"

I tested it on lnx and aix and $NEW_NAME got no input. So he cant mv anything because of a missing destination file. Dont know why.

Another problem is the find command itself. * is not working on lnx etc pp.


Hope some one can help here =)

kind regards
# 2  
Old 06-11-2013
echo and backquotes are missing here


Code:
NEW_NAME=`echo ${LINE} | sed -e 's/orig_//'`

# 3  
Old 06-11-2013
Better. Back tics are old way to do it.
Code:
NEW_NAME=$(echo ${LINE} | sed -e 's/orig_//')

# 4  
Old 06-11-2013
Thanks a lot both options are working very well.
Are the brackets replacing the backticks? Or do they have another meaning?

Now i am trying to get every single option to work because,
Code:
[..]sed -e 's/orig_//[...]

is just catiching /path/path/orig_*.file and not /path/path/file_orig.file
Can i use the "?" here for a single wildcard?

sed -e 's/?orig?// so he will catch every single string with an orig in there even some very large stuff that the find command will find :P

Code:
/path/path/file_orig/path/path/path/file.log
/path/path/file/path/path/path/file.log#

kind regards
# 5  
Old 06-11-2013
Brackets are used for testing.
Se more here:
Special Characters

Back tics `code` is replaced by more flexible parentheses $(code)
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. AIX

SUN TO AIX (UMASK)

I can't seem to get the umask command to work the same way in AIX that is worked in SUN. Can somebody tell me if I have to do something else. I'm using a userid to login. In that userid's profile. I add the umask command umask 003. I would like all files created by this ID to have... (2 Replies)
Discussion started by: wawa
2 Replies

2. AIX

SUN StorageTek tape drive with AIX 5.1

Hi, I have recently purchase a SUN Storage Tek desktop LTO 4 HH tape drive and connected to a IBM AIX 5.1 server. The server can detect the tape device. Can someone please advice urgently. Thanks (4 Replies)
Discussion started by: Caully
4 Replies

3. Solaris

SMIT i AIX Sun Solaris ?

i now when i want use the smit in AIX is possible but a ask if you has in sun same job in sun tel me please awating supports (3 Replies)
Discussion started by: Yalmalki
3 Replies

4. UNIX for Dummies Questions & Answers

File Transfer issues SUN - > AIX

Hi, I'm puzzled at how this could be. I'm trying to transfer some files from an Sun box to an AIX box via FTP. The file transfer goes fine until it reaches a file of about 150k then times out and fails. The FTP Does not seem to be able to transfer files of more than 150k! However, I can... (5 Replies)
Discussion started by: bbbngowc
5 Replies

5. AIX

Porting to AIX from Sun Solaris

Hi, When we tried to port our Pro*C programs from sun solaris to AIX, We get following error messages: The following library is not available... This library file is required for Pro*C Object Linking and Bin creation. /usr/lib/libnsl.so.1. Can anybody help us on this ? Regards rbs100 (1 Reply)
Discussion started by: rbs100
1 Replies

6. UNIX for Dummies Questions & Answers

system messages log (Sun and AIX)

Hello, I need a few explanation about the log files for system messages: /var/adm/messages and /var/log/syslog. As /var/adm/messages is empty on my machine, i need help. First, i would like to know what the difference between these 2 files is? Do they contain different kinds of system... (3 Replies)
Discussion started by: VeroL
3 Replies

7. UNIX for Dummies Questions & Answers

aix mksysb , hpux make_recovery sun?

hi, for aix and hpux, we have both mksysb and make_recovery for restoring to the former state after it was crashed. is there any equivalent to sun? any pointers will be appreciated. thanks (8 Replies)
Discussion started by: yls177
8 Replies
Login or Register to Ask a Question