How to insert a character in line in Special condition?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to insert a character in line in Special condition?
# 1  
Old 04-24-2009
How to insert a character in line in Special condition?

Hi,
I have a log file generated by a tool which has the following look :

/tmp/releases/directory/datefilename1_release_date.zip
/tmp/releases/directory/datefilename2_release_date.zip
/tmp/releases/directory/datefilename3_release_date.zip
/tmp/releases/directory/datefilename4_release_date.zip

Clearly you can identify the path generated for the each file by that tool is broken because there exists no "/" between date directory and the filename . I want to insert a "/" between the "date" and "filename" so that it becomes complete because this path is fed to another tool.
It should look like :

/tmp/releases/directory/date/filename1_release_date.zip
/tmp/releases/directory/date/filename2_release_date.zip
/tmp/releases/directory/date/filename3_release_date.zip
/tmp/releases/directory/date/filename4_release_date.zip

I tried with sed but did not know how to proceed. Please help . Thanks in advance.
# 2  
Old 04-24-2009
Assuming you have real dates instead of "release_date" in your file:

Code:
sed 's!\(.*date\)\(.*\)!\1/\2!'  file

Regards
# 3  
Old 04-24-2009
Hi ,
Thanks for your reply but it working partially . Actually the the line looks like
/tmp/night_release/proj_release_20090416Filename_release_1_0_20090416.zip

Need to look like

/tmp/night_release
/proj_release_20090416/Filename_release_1_0_20090416.zip

Regards,
# 4  
Old 04-24-2009
Should be something like:

Code:
sed 's!\(.*\)\(Filename.*\)!\1/\2!'  file

# 5  
Old 04-24-2009
Hi ,
Thanks for this reply it is working now. But is it good way to proceed ? because filename is different for different line In that case I have to write an another script to cut the file names and replace it with each time. Your suggetions?
# 6  
Old 04-24-2009
Try this:
Code:
sed s'!\(.*[0-9]\{8\}\)\(.*[0-9]\{8\}.*zip\)!\1/\2!' file

# 7  
Old 04-24-2009
Hi,
This time it worked perfectly fine. Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove blank space and insert special character

Hi Folks, I have a huge data of the below format abc #apple 1200 06/23 ghj #orange 1500 06/27 uyt #banana 2300 05/13 efg #vegetable 0700 04/16 After first 3 letters, i have 9 spaces and after fruit there are no specific fixed space, but it varies... (4 Replies)
Discussion started by: jayadanabalan
4 Replies

2. Shell Programming and Scripting

Insert New Line Character

Hi, If my first character of a line starts with 2 then after 5th charecter newline character should be inserted. Input.txt: a1234567890 2222300007 bsdfsdf888999999 ssdfkjskfdjskfdjd 2899900000000099999999999999 28887777 999999999999999999 Output.txt: a1234567890 22223 00007... (8 Replies)
Discussion started by: unme
8 Replies

3. Shell Programming and Scripting

Insert a character before a line

I have a file and I can get the line with a specific pattern. I want to inset # on start of the line. file.text ==== aa bb cc bb hh kk kk ll yy dd aa kk rr tt aa I want to comment out the line with contain "aa" after running the script file.text ==== #aa bb cc bb hh kk kk ll... (7 Replies)
Discussion started by: Biplab
7 Replies

4. Shell Programming and Scripting

How to insert line with between two consecutive lines that match special pattern?

I have following pattern in a file: 00:01:38 UTC abcd 00:01:48 UTC 00:01:58 UTC efgh 00:02:08 UTC 00:02:18 UTC and I need to change something like the following 00:01:38 UTC abcd 00:01:48 UTC XXXX 00:01:58 UTC efgh 00:02:08 UTC XXXX (6 Replies)
Discussion started by: jjnight
6 Replies

5. Shell Programming and Scripting

sort with condition and insert blank line

Hi, I have a file with no blank line anywhere Its a conf file, The lines between and starts with "#" should be sort out with the first three characters(characters are between (a-z)). and insert a blank space in between the uniq lines. For clear understanding ,pls find the below input file... (11 Replies)
Discussion started by: anil8103
11 Replies

6. Shell Programming and Scripting

parse special character in the line

Hi all, I have a file with some module names as below. Font::AFM Data::Grove ---> libxml-perl Net::LDAP ---> perl-ldap DBI XML .... ... .... and so on ... The file has some lines with the character " -->" . Now how can I cut only the last column of the line wherever "-->" is... (4 Replies)
Discussion started by: vijaya2006
4 Replies

7. Shell Programming and Scripting

Insert a special character $ in place of extra spaces

Hi Experts, I have called some.txt with the following content. oracle HYRDSRVIHUB01 pts/0 TESTIHUB 07-JUN-10 CREATE TABLE TESTIHUB PHONE ... (12 Replies)
Discussion started by: naree
12 Replies

8. UNIX for Dummies Questions & Answers

Insert character in the line

Hi All, I have below type file. abc|asd|pqr|2|2|2 asc|qwe|scf|5|4|4 Pipe location and count is dynamic and coming from a variable. I want to change it to below files. (chnage the first pipe to 3 pipes) abc|||asd|pqr|2|2|2 asc|||qwe|scf|5|4|4 (chnage the second pipe to 4 pipes)... (1 Reply)
Discussion started by: swat
1 Replies

9. Shell Programming and Scripting

How to filer a line in special condition?

Hi, I hava log file which has the following output : Created RELEASE in dist/filename_release_1_0_20090210.zip Created RELEASE in dist/filename_release_1_1_20090210.zip Created RELEASE in dist/filename_release_1_3_20090210.zip Created RELEASE in... (6 Replies)
Discussion started by: bhaskar_m
6 Replies

10. UNIX for Dummies Questions & Answers

[OpenServer 5]Line Printing and special character (é @)

Hello, On Sco OpenServer 5, i want to print using the lpr command, no CUPS installed. I print on an HP LaserJet 4050 on LAN (IP 192.168.x.x) the printer is installed by HP Network Printer service. it works fine, but Specials characters, like é, @ or ° print bad characters. Is there... (5 Replies)
Discussion started by: tankd
5 Replies
Login or Register to Ask a Question