file name Manipulation using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file name Manipulation using sed
# 1  
Old 03-10-2005
Java file name Manipulation using sed

Hi,

I have a file name, for which I want to strip out the first bit and leave the rest...

So I want to take the file name .lockfile-filename.10001 ,strip it and have only filename.10001 ...

Thanking you all inadvance,

Zak
# 2  
Old 03-10-2005
Quote:
Originally Posted by Zak
Hi,

I have a file name, for which I want to strip out the first bit and leave the rest...

So I want to take the file name .lockfile-filename.10001 ,strip it and have only filename.10001 ...

Thanking you all inadvance,

Zak
what separates the 'first bit' from the 'rest of the bits'?

In case it's a dash "-":
Code:
echo '.lockfile-filename.10001' | sed -e 's/^[^-][^-]*-\(.*\)/\1/'

# 3  
Old 03-10-2005
Cool, that works fine...

Thanks very much...


I just need to work that into my script... Smilie
# 4  
Old 03-10-2005
If you're using a good shell (such as ksh), you can use the builtin functions of the shell to perform manipulation such as this (which will increase performance), for example, to rename the file from .lockfile-filename.10001 to filename.10001
Code:
#!/bin/ksh

filename=".lockfile-filename.10001"
mv ${filename} ${filename##*-}

Cheers
ZB
# 5  
Old 03-14-2005
Quote:
Originally Posted by Zak
Hi,

I have a file name, for which I want to strip out the first bit and leave the rest...

So I want to take the file name .lockfile-filename.10001 ,strip it and have only filename.10001 ...

Thanking you all inadvance,

Zak
You can simply use cut + mv for this operation as,
Code:
mv .lockfile-filename.10001 $(echo .lockfile-filename.10001 | cut -d"-" -f2)

HTH.
# 6  
Old 03-14-2005
Hello vgersh99,

can you please explain the script ...
Quote:
sed -e 's/^[^-][^-]*-\(.*\)/\1/'
it will very good when it is explained..

Thanks in advance

Esham
# 7  
Old 03-14-2005
To explain the pattern of ^[^-][^-]*-\(.*\) then,

^ says from begin

[^-] - Anything except -
[^-] [^-]* - Anything except - 0 or more times
- hypon
\(.*\) - Upto end

We can do your requirement simply as,

sed -e 's/^[^-]*-\(.*\)$/\1/'

Example:
# echo .lockfile-filename.10001 | sed -e 's/^[^-]*-\(.*\)$/\1/'
filename.10001

HTH.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File manipulation place 0 before the number using sed

I'm new with sed, and i am really confused with slashes, backslashes, parentheses, I've tried reading some beginner's guide, but still trouble fixing this problem, do you have any tips where or what to read to learn more about sed? can you also help me with my problem? Note: I was tasked to use... (4 Replies)
Discussion started by: akopocpoypoy
4 Replies

2. Shell Programming and Scripting

Text manipulation with sed - Advanced technic

Hello everybody, I have the following input file: START ANALYSIS 1 DATA LINE DATA LINE DATA LINE DATA LINE Libray /home/me/myLibrary Source library_name_AAAAA DATA LINE DATA LINE DATA LINE BEGIN SOURCE ANALYSIS Function A Function B Function C Function D (4 Replies)
Discussion started by: namnetes
4 Replies

3. Shell Programming and Scripting

sed for string manipulation

I have a file which contains contents like below proxy.config.cluster.mc_group_addr 224.0.1.37 proxy.config.log.logging_enabled 3 proxy.config.log.squid_log_enabled 1 Need to modify to 'proxy.config.cluster.mc_group_addr': '224.0.1.37' 'proxy.config.log.logging_enabled': '3'... (10 Replies)
Discussion started by: esham
10 Replies

4. Shell Programming and Scripting

sed flat file manipulation

Hello, I have a large flat file where i need to change data in columns 131-133 based on what is in columns 172-173. I am not sure if I need to read the file line by line and make the change or if I can do this in a single statement. thank you (3 Replies)
Discussion started by: gblmin
3 Replies

5. Shell Programming and Scripting

Manipulation with the string using sed

hello All, When I run find command on certain directory I may get one of the following output depending on configuration A. ./rel/prod/libpam.a B. ./rel/fld/libpam.a C. ./deb/detail/libpam.a D. ./deb/err/libpam.a I want to get output as below A. rel/prod B.... (2 Replies)
Discussion started by: anand.shah
2 Replies

6. Shell Programming and Scripting

setter and getter functions for file manipulation with sed

Hi, I would really appreciate some help, I couldn't nail my problem: I would like to create some setter and getter functions to make my life easier. my sample file contains: keyword - some tabs - value - semicolon number 12.1; float .3; double 12; real 12.2324; stuff .234; decimal... (5 Replies)
Discussion started by: Toorop
5 Replies

7. Shell Programming and Scripting

SED/AWK file read & manipulation

I have large number of data files, close to 300 files, lets say all files are same kind and have extension .dat , each file have mulitple lines in it. There is a unique line in each file containing string 'SERVER'. Right after this line there is another line which contain a string 'DIGIT=0',... (4 Replies)
Discussion started by: sal_tx
4 Replies

8. Shell Programming and Scripting

File manipulation with AWK and SED

Hello How do i check that correct input files are used while using AWk and SED for file manipulation? e.g awk '/bin/ {print $0 }' shell.txt sed 's/hp/samsung/' printers.txt how do i ensure that the correct input files I am working with are used? (5 Replies)
Discussion started by: Pauline mugisha
5 Replies

9. Shell Programming and Scripting

sed string manipulation

hi I am using sed to split a string this string is 11byteabc I would like to just get the numeric digits. echo "11byteabc" | sed 's/*// returns 11byteabc only solution that works is repeating number of times for the letters which is pointless grateful for any suggestions thanks (4 Replies)
Discussion started by: speedieB
4 Replies

10. Shell Programming and Scripting

How to use sed for string manipulation

Hi, I would like to know How to use use sed for manipulating string for the following situation. Basically my objective is to check validity of the filename in my shell script. I am getting a parameter like this for my shell script. Check my folder is having some space. $1=/root/krishna... (2 Replies)
Discussion started by: hikrishn
2 Replies
Login or Register to Ask a Question