Duplicate each field in a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Duplicate each field in a text file
# 1  
Old 08-11-2011
Duplicate each field in a text file

Hello all,

I am searching for a solution to the following problem:

Given input such as this:
Quote:
entry1 entry2 entry3 entry4
I would like to find a way to output this:

Quote:
entry1 entry1 entry2 entry2 entry3 entry3 entry4 entry4
Thanks in advance!
# 2  
Old 08-11-2011
Code:
echo 'entry1 entry2 entry3 entry4' |perl -alne 'print  map {$_ x 2} map{$_." "} @F'
entry1 entry1 entry2 entry2 entry3 entry3 entry4 entry4

This User Gave Thanks to yinyuemi For This Post:
# 3  
Old 08-11-2011
Code:
 sed 's/[^ ]*/& &/g' INPUTFILE


Last edited by yazu; 08-11-2011 at 10:27 PM.. Reason: Right solution
This User Gave Thanks to yazu For This Post:
# 4  
Old 08-11-2011
Code:
echo entry1 entry2 entry3 entry4 |awk '{for(;++i<=NF;)$i=$i FS $i}1'

This User Gave Thanks to danmero For This Post:
# 5  
Old 08-12-2011
sed 's/[^ ]*/& &/g' INPUTFILE
This User Gave Thanks to anuragpgtgerman For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum duplicate values in text file through awk between dates

I need to sum values in text file in case duplicate row are present with same name and different value below is example of data in file i have and format i need. Data in text file 20170308 PM,U,2 PM,U,113 PM,I,123 DA,U,135 DA,I,113 DA,I,1 20170309 PM,U,2 PM,U,1 PM,I,123 PM,I,1... (3 Replies)
Discussion started by: Adfire
3 Replies

2. Shell Programming and Scripting

Removing duplicate sequences and modifying a text file

Hi. I've tried several different programs to try and solve this problem, but none of them seem to have done exactly what I want (and I need the file in a very specific format). I have a large file of DNA sequences in a multifasta file like this, with around 15 000 genes: ... (2 Replies)
Discussion started by: 4galaxy7
2 Replies

3. Shell Programming and Scripting

How to remove duplicate text blocks from a file?

Hi All I have a list of files which will have duplicate list of blocks of text. Following is a sample of the file, I have removed the sensitive information from the file. All the code samples starts from <TR BGCOLOR="white"> and Ends with IP address and two html tags like this. 10.14.22.22... (3 Replies)
Discussion started by: mahasona
3 Replies

4. Shell Programming and Scripting

Duplicate rows in a text file

notes: i am using cygwin and notepad++ only for checking this and my OS is XP. #!/bin/bash typeset -i totalvalue=(wc -w /cygdrive/c/cygwinfiles/database.txt) typeset -i totallines=(wc -l /cygdrive/c/cygwinfiles/database.txt) typeset -i columnlines=`expr $totalvalue / $totallines` awk -F' ' -v... (5 Replies)
Discussion started by: whitecross
5 Replies

5. Shell Programming and Scripting

How to sum particular field in text file?

how to sum particular field in text file i am having text file like 222|4000|abc 333|5000|xyz 444|6000|mno i want sum of second field i.e 4000+5000+6000 can u pls help (3 Replies)
Discussion started by: suryanarayana
3 Replies

6. Shell Programming and Scripting

Shellscript to sort duplicate files listed in a text file

I have many pdf's scattered across 4 machines. There is 1 location where I have other Pdf's maintained. But the issues it the 4 machines may have duplicate pdf's among themselves, but I want just 1 copy of each so that they can be transfered to that 1 location. What I have thought is: 1) I have... (11 Replies)
Discussion started by: deaddevil
11 Replies

7. Shell Programming and Scripting

How to find Duplicate Records in a text file

Hi all pls help me by providing soln for my problem I'm having a text file which contains duplicate records . Example: abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 tas 3420 3562 ... (1 Reply)
Discussion started by: G.Aavudai
1 Replies

8. Shell Programming and Scripting

duplicate line in a text file

i would like to scan file in for duplicate lines, and print the duplicates to another file, oh and it has to be case insensitive. example line1 line2 line2 line3 line4 line4 outputfile: line2 line4 any ideas (5 Replies)
Discussion started by: nixguy
5 Replies

9. Shell Programming and Scripting

Eleminating Duplicate IPs from a text file

Hey Guys I need to eleminate duplicate IP's from a text file using bash.Any suggestions.Appreciate your help guys. --CoolKid (4 Replies)
Discussion started by: coolkid
4 Replies

10. UNIX for Advanced & Expert Users

Duplicate records from oracle to text file.

Hi, I want to fetch duplicate records from an external table to a text file. Pls suggest me. Thanks (1 Reply)
Discussion started by: shilendrajadon
1 Replies
Login or Register to Ask a Question