Using SED to copy/paste with slashes and tabs.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using SED to copy/paste with slashes and tabs.
# 1  
Old 08-10-2012
Using SED to copy/paste with slashes and tabs.

I have:

Code:
2012/01_January/Kite[TAB HERE]/foldername/otherfoldername/placeholder[TAB HERE]Blue

I want to end up with:

Code:
/foldername/otherfoldername/2012/01_January/Kite/Blue

Basically take everything before the first tab and put it in the place of the consistently named word placeholder and add a slash in place of the last tab. I am using sed on Solaris.

Thanks!


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-10-2012 at 05:44 PM.. Reason: code tags
# 2  
Old 08-10-2012
Try:
Code:
sed 's/\(.*\)\t\(.*\)placeholder\t\(.*\)/\2\1\/\3/' file

# 3  
Old 08-10-2012
This works on Solaris, the @@@@ is an actual TAB:
Code:
> cat t
2012/01_January/Kite@@@@/foldername/otherfoldername/placeholder Blue


Code:
> sed -e 's#^\([0-9]\{4\}/[0-9]\{2\}_.\{1,9\}/.\{1,\}\)@@@@\(/.\{1,\}/.\{1,\}/\).\{1,\}@@@@\(.\{1,\}\)#\2\1/\3#' t
/foldername/otherfoldername/2012/01_January/Kite/Blue

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use sed/awk to do like copy and paste

I have rrd file which is have the gaps and I want to fill it out with some value , I've got 10 NaN record and I try to populate data from 10 records be for NaN to change instead of NaN :( <!-- 2016-05-19 14:10:00 CST / 1463638200 -->... (11 Replies)
Discussion started by: boobytrap
11 Replies

2. Shell Programming and Scripting

Copy n paste n times

I have one mainframe copy book where I want to copy n times depend on occurs which mention below. Example: Below highlighted row mention “occurs 2 times” so I need to copy 2 times till next label 10. C14992 10 FILLER PIC X(2835). 01 ... (7 Replies)
Discussion started by: srivalli
7 Replies

3. Shell Programming and Scripting

How to use sed when a match has forward slashes

I'm trying to replace an alias with its match using sed but the match contains forward slashs so it causes the sed command to throw a garbled message.. cmd_list.txt sample AIX_myserver_1011_vintella.sudoers_cmndalias sample I'm trying to use the below but like I say it throws a... (5 Replies)
Discussion started by: Jazmania
5 Replies

4. Shell Programming and Scripting

Copy and paste data

I need to copy from specified lines and paste the data into several other lines. XX123450008 xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x XX123451895 xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x ...... XX123452012 xx.x xx.x xx.x xx.x xx.x xx.x xx.x... (13 Replies)
Discussion started by: ncwxpanther
13 Replies

5. Shell Programming and Scripting

sed help - search/copy from one file and search/paste to another

I am a newbie and would like some help with the following - Trying to search fileA for a string similar to - AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3 I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

6. Shell Programming and Scripting

Copy and Paste to a new document

Hello, I am quite new to shell scripting so don't know all the tools available. What I'm trying to do is open a file optimal.txt search for objectiveValue and copy the number in quotes next to it. e.g. ... solutionName="incumbent" solutionIndex="-1" objectiveValue="13246" ... (6 Replies)
Discussion started by: StephanR
6 Replies

7. Shell Programming and Scripting

sed copy paste

Hello, I have this path and file: /dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txt I want to end up with: /dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txtTHIS_SPOT Take the dir after the 10th slash, add a tab at the end and paste the dir it copied. Thanks (4 Replies)
Discussion started by: crowman
4 Replies

8. Shell Programming and Scripting

sed - how to remove trailing slashes

I know you can remove trialing slashes using: #echo "/tmp/one/two/three////" | sed "s,/$,," /tmp/one/two/three/// But I want to know how to make it remove all trialing flashes in the front, and in the start, so the end result is: tmp/one/two/three Anyone have any idea how to do this... (6 Replies)
Discussion started by: EXT3FSCK
6 Replies

9. Shell Programming and Scripting

copy/paste with awk

Hi everybody, I have two XML files. I am working on a script that could copy and paste the contents of the first xml file to the desired location in the second xml file. Here is my first XML file. This is the second XML file. Finaly, I wnat to obtain something like that : ... (2 Replies)
Discussion started by: lsaas
2 Replies

10. UNIX for Dummies Questions & Answers

sed command for using with back slashes

hi all, im trying to use a sed command to remove all occurenes of \p\g what i used so far is : sed 's!\p\g!!g' file but this doesnt work ? Any ideas, thanks for helping. (2 Replies)
Discussion started by: seaten
2 Replies
Login or Register to Ask a Question