Replicating content using sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replicating content using sed
# 1  
Old 01-03-2012
Replicating content using sed

if we want to replicate the content of the file twice, then we can use
Code:
sed 'p' filename

In the same way, if i want to replicate the content thrice or 4 times, how we can achieve in SED?
Thanks
# 2  
Old 01-03-2012
one way .. Include $0 as per your wish ..
Code:
$ awk '{print $0"\n"$0"\n"$0}' infile

https://www.unix.com/shell-programmin...ines-file.html
This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 01-03-2012
yes. AWK is the proper solution for this scenario. Out of curious, i have tried in sed and the below command works fine for single input, But i dont know how to incorporate to a file
Code:
echo hi|sed -e '1,2p' -e '1p'

Thanks
# 4  
Old 01-03-2012
sed '
{
p
p
} '
# 5  
Old 01-03-2012
Quote:
Originally Posted by tarun_agrawal
sed '
{
p
p
} '

is this really working for you?
The command gets garbled .
i have tried:
Code:
echo hi|sed '{ p p}'
echo hi|sed '{pp}'

# 6  
Old 01-03-2012
@pandeesh:

Commands in same line must be separated with ';'
Code:
$ echo hi|sed '{p;p}'

Regards,
Birei
This User Gave Thanks to birei For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Glusterfs not replicating

0 down vote favorite I have replicated glusterfs on two servers, if i create file on one server it doesnt reflect on other, if i try to heal the volume on node2 i get this error Commit failed on node2. Please check log file for details. glustershd.log E 0-test-client-3: connection to... (0 Replies)
Discussion started by: davidbob
0 Replies

2. Shell Programming and Scripting

Replicating certain lines in a textfile

I am very new to to shell scripting and facing a problem that I can't seem to solve. I want to write a bash script that edits file1.txt and saves it as file2.txt. This is what the files should look like: file1: textline1 textline2 startCopy copyThis endCopy textline3 textline4 file2: ... (6 Replies)
Discussion started by: sandy90
6 Replies

3. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

4. Shell Programming and Scripting

Replicating jobs, renaming outout

Can anyone tell me if it's possible to write a script that will repeat the same job several times but give the output a slightly different name each time (i.e. change or add a number at the end of the output file)? Here is the script I use to run a single job: #!/bin/bash #PBS -N job0 #PBS -l... (1 Reply)
Discussion started by: peterjb100
1 Replies

5. Shell Programming and Scripting

Replicating rows by splitting column in text file

Hi, I have flat file with following format Col1, Col2, Col3, Col4 --------------------------------- r1_c1, r1_c2, r1_c3, abc | def | efg r2_c1, r2_c2, r2_c3, abcwdw | dweweef | efg | ijk r3_c1, r3_c2, r3_c3, abaac ........... The first three columns contain only one entry per... (3 Replies)
Discussion started by: nick2011
3 Replies

6. UNIX for Dummies Questions & Answers

Replicating many rows in unix

Hi If my input is abcdefgh ijklmnop then the output should be: abcdefgh abcdefgh abcdefgh abcdefgh ijklmnop (6 Replies)
Discussion started by: pandeesh
6 Replies

7. Shell Programming and Scripting

sed, awk [TAG]$content[/TAG] How to get var in $content in textfile?

Hello, I got a Qstion. Im posting to a phpbb forum with bash and curl.. i have a text file with the following tags that i post to the forum: $var1 $var2 $var3 How can i with sed or awk put var content from shell script between the ... in the... (7 Replies)
Discussion started by: atmosroll
7 Replies

8. AIX

Command for replicating a directory

Morning all, Is there a command on AIX that can replicate/synchronise two directories? I'm after functionality similar to robocopy on Windows. Scenario: I have a directory of Oracle forms for my production system and one for my dev system, these directories start off identical. The forms... (1 Reply)
Discussion started by: huggie
1 Replies

9. Shell Programming and Scripting

how to change the content thru sed.....

Hi Everybody, Another headache form myside, i have a file name noname.txt having content as CS007=NEW and i have to write a scipt which will take the parameters as update,delete... with the 1st field of noname.txt (i.e. here CS007) whose objective is to change the 2nd field of noname.txt... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

10. UNIX for Dummies Questions & Answers

replicating restricted sam users

I'm in the process of setting up two new HP-UX 11.23 i64 servers. On my existing server (HP-UX B.11.0) we have several users defined to have restricted sam access. I'm having trouble finding those definitions and copying them over to the new servers. Is this possible - to just copy over the... (1 Reply)
Discussion started by: LisaS
1 Replies
Login or Register to Ask a Question