Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

repeat string in a line using sed

Tags:

sed

I would like to repeat each line's content of a file, any quick solution using sed.

supposed the input file is

abc
def
123

The expected ouput is:

abcabc
defdef
123123

like image 933
user343811 Avatar asked May 18 '10 08:05

user343811


4 Answers

sed 's \(.*\) \1\1 ' infile
like image 131
Dimitre Radoulov Avatar answered Nov 20 '22 08:11

Dimitre Radoulov


This might work for you:

echo -e 'aaA\nbbB\nccC' | sed 's/.*/&&/'
aaAaaA
bbBbbB
ccCccC
like image 42
potong Avatar answered Nov 20 '22 08:11

potong


sed 'h;G;s/\n//' file.txt
like image 31
Dennis Williamson Avatar answered Nov 20 '22 09:11

Dennis Williamson


It's even simpler if you take advantage of the variable \0, which holds the string that was matched:

sed 's/.*/\0\0/'

like image 2
Alex Henrie Avatar answered Nov 20 '22 09:11

Alex Henrie