difficult sed command


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users difficult sed command
# 15  
Old 09-29-2006
Ok im stuck on the same command again!
I want to put a filename after each of the lines, but the filename obviously contains '/' so I need to use a different delimiter, but when I change:

sed '/\(.*\)/{G;s/\(.*\)\(\n\)/\1\\
new\1\\
new\1\\
directiory/and/file/name /;}' test > temp

to something like:

sed '@\(.*\)@{G;s@\(.*\)\(\n\)@\1\\
new\1\\
new\1\\
directiory/and/file/name @;}' test > temp

it doesnt work! It says 'sed: garbled command....'

Can anyone help me?
# 16  
Old 09-29-2006
Try something like...
Code:
$ printf "1\n2\n3\n" | awk '{print $0 ORS "new" $0 ORS "new" $0 ORS "/dir/and/file/name"}'
1
new1
new1
/dir/and/file/name
2
new2
new2
/dir/and/file/name
3
new3
new3
/dir/and/file/name

# 17  
Old 09-29-2006
Thats great!
How would it be used if i wanted the first line somewhere in the middle of the rest of the line eg:

input:
line1
line2
line3

output:
line1
create|vt|line1
populate|vt|line1|eng|D. Clark

line2
create|vt|line2
populate|vt|line2|eng|D. Clark

line3
create|vt|line3
populate|vt|line3|eng|D. Clark

Thanks for your help!
# 18  
Old 09-29-2006
Its ok, I sorted it in the end!

For anyone else with the same problem, you dont need to change the first 2 delimiters, only the ones after the s! The following code works!

code:
sed '/\(.*\)/{G;s@\(.*\)\(\n\)@#\1\2new\1\\
new\\
new\\
newfile/directory/andname\\
@;}' test > temp
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Difficult in analyzing an algorithm

Hello, I was reading Heuritics text and came across an algorithm below. Finding hard to analyze it can any one help me out below... How to analyze if I take say no. of types are 5 and each type has say 20 coins. thanks. Let {c1, c2...cn=1} be a set of distinct coin types where ci is... (1 Reply)
Discussion started by: sureshcisco
1 Replies

2. UNIX for Dummies Questions & Answers

difficult problem with function declaration

Hello, I have a problem with the declaration of a function. This is how I declare the function : c:63: void foo(threadpool *tp,void (*func)(void*), (void*)arg); Inside main, I call it like this: main(){ .......... threadpool y; c:104: ... (4 Replies)
Discussion started by: garag11
4 Replies

3. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

4. UNIX for Advanced & Expert Users

File alignment and performances... (difficult)

Hello ! I will use my best english possible to explain my objective. I'm french so pardon for the lack of precision... So, what i would like to do in shell script (but you will possibly answer ''not possible in script'' have to use low level langage or something like that) is described below.... (3 Replies)
Discussion started by: Gnaag
3 Replies

5. Shell Programming and Scripting

difficult nawk to understand

I found a command who prints x lines before and after a line who contain a searched string in a text file. The command is : nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=2 a=4 s="string" file1 It works very well but I can't understand the syntax, too difficult with... (2 Replies)
Discussion started by: ahmad.diab
2 Replies

6. UNIX for Dummies Questions & Answers

so difficult question about using grep

en...how to grep some words from some file, the goal is that, we donot want the words are exactly 9 charactor, and want to grep from some words that are longer than 9 and it contain a substring that with 9 different charactors (2 Replies)
Discussion started by: shrimpy
2 Replies

7. Shell Programming and Scripting

A difficult script (for me)

Hi, I'm a beginners, this is one of my first script, it's easy, but I don't know how to write this script: The script receive in input 4 parameters: 1) user_name 2) r and/or w and/or x ( rwx, rw, x, ....) 3) u and/or g and/or o ( u, uo, ugo, ...) 4) the path name The script print a... (2 Replies)
Discussion started by: DNAx86
2 Replies

8. Solaris

difficult time differences

:rolleyes: Hi, How to take the time diffence between start and finish time from a log file? It is like ..... started at Jun 20 23:20 . . ..... finished at Jun 21 01:40 Tryed so many ways but failed to ger exact way. :confused: Your help will be honoured. Ta........Lokesha (1 Reply)
Discussion started by: Lokesha
1 Replies

9. UNIX for Advanced & Expert Users

Difficult Filtering Problem

Sir, I have a file containing say 1000 lines that contain 100 paragraphs of 10 lines each separated by blank lines.I have to match a pattern or a string "hdfhasdjkasdhs" and print the complete paragraphs containing these strings.I can do this with the help of line editor ex,but how can I use... (1 Reply)
Discussion started by: Piyush
1 Replies
Login or Register to Ask a Question