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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace './' with '/home/' in file
# 8  
Old 05-04-2009
Quote:
Originally Posted by vgersh99
Code:
echo './tmp/1.jpg' | sed 's#^[.]#/home#'

Can you briefly explain this? I don't understand what prevents this from replacing all instances of '.'.

devtakh, although it took me a minute to figure out how to use this witha longer path, it works very well. Thank you!
# 9  
Old 05-04-2009
Quote:
Originally Posted by brianm
Can you briefly explain this? I don't understand what prevents this from replacing all instances of '.'.

devtakh, although it took me a minute to figure out how to use this witha longer path, it works very well. Thank you!
Code:
echo './tmp/1.jpg' | sed 's#^[.]#/home#'

'^' signifies 'the beginning of a line.
# 10  
Old 05-07-2009
Quote:
Originally Posted by vgersh99
Code:
echo './tmp/1.jpg' | sed 's#^[.]#/home#'

'^' signifies 'the beginning of a line.
But removing the ^ still only replaces the first instance?

Lastly, I'm trying to remove the 1.jpg and just leave /home/tmp/, but I am not able to acheive this doing the following:
Code:
echo '/home/1.jpg' | sed 's#/*[.]jpg##'

I am left with the trailing '1'.

Last edited by brianm; 05-07-2009 at 10:07 PM..
# 11  
Old 05-07-2009
if you have Python, here's an alternative
Code:
import fileinput
for line in fileinput.FileInput("file",inplace=1):
    line=line.strip()
    if line.startswith("./"):
        print line.replace("./","/home/")

output:
Code:
# ./test.py
/home/tmp/1.jpg
/home/tmp/2.jpg

# 12  
Old 05-08-2009
Quote:
Originally Posted by brianm
But removing the ^ still only replaces the first instance?

Lastly, I'm trying to remove the 1.jpg and just leave /home/tmp/, but I am not able to acheive this doing the following:
Code:
echo '/home/1.jpg' | sed 's#/*[.]jpg##'

I am left with the trailing '1'.
Code:
echo '/home/1.jpg' | sed 's#\(.*\)/.*$#\1#'

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