Replace './' with '/home/' in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace './' with '/home/' in file
# 1  
Old 05-03-2009
Replace './' with '/home/' in file

I have been looking for a way to do this with sed and awk but could not get the results I need. I have a single file with multiple lines in which I need to replace a './' with '/home/'.

For example:
./tmp/1.jpg
./tmp/2.jpg
Should become:
/home/tmp/1.jpg
/home/tmp/1.jpg
Any help is apprecaited!
# 2  
Old 05-03-2009
Code:
sed 's/\./\/home/g' file > newfile

cheers,
Devaraj Takhellambam
# 3  
Old 05-03-2009
Quote:
Originally Posted by devtakh
Code:
sed 's/\./\/home/g' file > newfile

cheers,
Devaraj Takhellambam
This is where I got stuck with sed and moved onto awk...

Using your suggestion took this source:
./999/999.jpg
And generated the following output:
home/999/999homejpg
This removed the first '/' and replaced the second instance of the '.' (replacing the second instance of '.' with 'home'). I need to replace './' with '/home/' or a longer directory like '/home/username/'.
# 4  
Old 05-04-2009
Try This ...

sed "s/\.\/tmp/\/home\/tmp/g" filename > newfile
# 5  
Old 05-04-2009
Quote:
Originally Posted by manish6725
Try This ...

sed "s/\.\/tmp/\/home\/tmp/g" filename > newfile
That actually didn't have any effect... Smilie
# 6  
Old 05-04-2009
Quote:
Originally Posted by brianm
This is where I got stuck with sed and moved onto awk...

Using your suggestion took this source:
./999/999.jpg
And generated the following output:
home/999/999homejpg
This removed the first '/' and replaced the second instance of the '.' (replacing the second instance of '.' with 'home'). I need to replace './' with '/home/' or a longer directory like '/home/username/'.
Ah, I didn't notice the . extension. you can searc for ./ and replace it with /home/

Code:
sed 's/\.\//\/home\//g' filename > outfile

or
Code:
sed 's/^\.\//\/home\//g' filename > outfile


cheers,
Devaraj Takhellambam
# 7  
Old 05-04-2009
Code:
echo './tmp/1.jpg' | sed 's#^[.]#/home#'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot run this .java file from the home directory??

I wrote a simple test.java program in vi. I know it compiles correctly because I went into the directory where test.java was and compiled it and it created a java.class. I then ran test.java by staying in the same directory where it was and it worked great. However, when i backed out of the... (3 Replies)
Discussion started by: syregnar86
3 Replies

2. Shell Programming and Scripting

Looking for config file in home directory first??

hi, i have written a shell script inside which i am using a pgp command to encrypt a file. when pgp command is run , there is a /.pgp/pgp.cfg file in my home directory. i logged into the unix server with my userid, when i run the script from the command prompt, pgp is successful, since i am... (5 Replies)
Discussion started by: Little
5 Replies

3. UNIX for Dummies Questions & Answers

BackUp Home/Creating User from File

Hi! I want to test something to learn Shell scripting better. 1) How can I make a BackUp from all users and groups homedirectory? I want to save that backup in an archiv. Can I choose how to name the backUp archiv? 2) Ok I want to make a file like csv, in this file are listed Users.... (3 Replies)
Discussion started by: CommanderLinux
3 Replies

4. UNIX for Advanced & Expert Users

Keeping your Home file permissions correct

I have been a UNIX user for a long time, and in that time I have been looking for a program to set/reset all the file permissions of a complex directory hierarchy (my home) according to a configuration file of rules. That is not the simple find-xargs-chmod rule but a program (shell/perl/c)... (4 Replies)
Discussion started by: antofthy
4 Replies

5. Shell Programming and Scripting

cp -p /home/* home/exp/*.date not working please help

:( ---------- Post updated at 01:51 AM ---------- Previous update was at 01:50 AM ---------- Not working ---------- Post updated at 02:04 AM ---------- Previous update was at 01:51 AM ---------- cp -p /home/* home/exp/*.`date` i am using this (4 Replies)
Discussion started by: rishiraaz
4 Replies

6. Shell Programming and Scripting

how to list of file in home dir ?

I want to print all list of file in the home dir of the user in $i with full bath an owner and group and permissions (1 Reply)
Discussion started by: testman84
1 Replies

7. Solaris

how to change /export/home/user dir to /home /user in solaris

Hi all i am using solaris 10, i am creating user with useradd -d/home/user -m -s /bin/sh user user is created with in the following path /export/home/user (auto mount) i need the user to be created like this (/home as default home directory ) useradd -d /home/user -m -s /bin/sh... (2 Replies)
Discussion started by: kalyankalyan
2 Replies

8. UNIX for Dummies Questions & Answers

How to get the latest modified file name in /home directory?

I only know how to list all sub-directories or files in specified directory. I don't know how to order them by modified date, furthermore, I don't know how to get the top one file in the sorted list. Wish you can do me a favor. Thanks in advance! (3 Replies)
Discussion started by: crest.boy
3 Replies

9. Shell Programming and Scripting

List /home directories in a file

Hi, i was looking at a unix paper i found and one of the tasks was to create a file called 'usernames' that contains a list of all directories in /home. This file should be located in the /home/userinfo directory. How would i go about doing this without changing directories from the home... (2 Replies)
Discussion started by: warlock129
2 Replies

10. Shell Programming and Scripting

Replace missing standard folders from home directories.

Hi, I want to develop a script to replace missing folders from home directories. These may have been deleted by the user. A standard home directory will have these folders in it and nothing else: Desktop, Documents, Downloads, Library, Movies, Music, Pictures, Public, Sites I also want to... (3 Replies)
Discussion started by: z399y
3 Replies
Login or Register to Ask a Question