Adding a running sequence number while appending 2 files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Adding a running sequence number while appending 2 files
# 1  
Old 11-04-2010
Bug Adding a running sequence number while appending 2 files

Hi,

I have to append 2 files and while appending i need to add a running sequence number (counter ) for each line at the first column.

For e.g. If file x contains details as below.
Tom
Dick
Harry
Charlie
and file y contains
Boston
Newyork
LA
Toledo

Then the new file should like with a running sequence number inserted at first column

1 Tom Boston
2 Dick Newyork
3 Harry LA
4 Charlie Toledo

Please suggest how I can do this.
# 2  
Old 11-04-2010
Code:
 
$ cat file1 
Tom 
Dick 
Harry 
Charlie 
$ cat file2 
Boston 
Newyork 
LA 
Toledo 
$ paste file{1,2} | cat -n
      1  Tom     Boston
      2  Dick    Newyork
      3  Harry   LA
      4  Charlie Toledo

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add sequence number to files

Hi I am having files in my dir ,some times it vary ,i need to assign sequence number with gunzip the file name .Please advise ex: file1.gz file1111.gz file11111.gz file1111111.gz expecting out output file_1 file1111_2 file1111111_3 i written this script ,its not working what i... (3 Replies)
Discussion started by: mohan705
3 Replies

2. Shell Programming and Scripting

Appending sequence number at the end of file name

hi team, i need a script for renaming a file with sequence number. script get a file from one directory'/home/billing/Cmm/sms/sms_tmp' append sequence no at the end of file name and move a file to other directory/home/billing/Cmm/sms/. actual file is cdr201508271527 file after renaming ... (3 Replies)
Discussion started by: mfaizan40
3 Replies

3. Shell Programming and Scripting

Need Help in adding sequence number to a file

Hi All , I have a file which contains data(comma separated) in below format : 500,Sourav ,kolkata ,8745775020,700091 505,ram,delhi ,9875645874,600032 510 ,madhu ,mumbai ,5698756430 ,500042 515 ,ramesh ,blore ,8769045601 ,400092 I want to add unique sequence number at the start of each... (7 Replies)
Discussion started by: STCET22
7 Replies

4. Shell Programming and Scripting

Help with appending random sequence to huge CDR file

Hi, I am in a terrible emergency. I have multiple cdr files with line count >6000. I need to append |0| | | | | | | |random| to end of each line. The random number should never repeat. Please help with a shell script to process all cdr's in a directory with above requirement. (23 Replies)
Discussion started by: shiburnair
23 Replies

5. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

6. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

7. UNIX for Dummies Questions & Answers

Adding Sequence Number to file

Hi All, I need to create a script which checks for a particular file for eg.kumar1.txt. If kumar1.txt is already exist the script should increment the file name as kumar2.txt and so on. Please Advise. Thanks & Regards, Kumar66 (2 Replies)
Discussion started by: kumar66
2 Replies

8. Shell Programming and Scripting

How to split a file with adding sequence number and extension.

I have a file name -HRCFTSIN05PLA1602100430444444 my requirement is to split the file in 10000 count each file and to add sequence number.rch at the end of each file. output should be in this format HRCFTSIN05PLA160210043044444401.rch HRCFTSIN05PLA160210043044444402.rch... (4 Replies)
Discussion started by: abhigrkist
4 Replies

9. Shell Programming and Scripting

Adding a sequence number within a file

Can someone please help. I need to add a sequence number to the start of each line of a file. It needs to be 6 characters long. ie 000001 next line starts 000002 etc. (4 Replies)
Discussion started by: Dolph
4 Replies

10. UNIX for Dummies Questions & Answers

appending variable number of files

In a particular path of a server I have number of files.The files are generated every date with a date_mth stap on this.There are different files for different clients. For example in /data1 path i have X_0416_Score Y_0416_Score Z_0417_Score X_0417_Score A_0417_Score If i will run the... (1 Reply)
Discussion started by: dr46014
1 Replies
Login or Register to Ask a Question