Creating sequence number as per records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating sequence number as per records
# 8  
Old 11-15-2016
Quote:
Originally Posted by rahulsk
Hi,
Code given by Ravinder was fine. But had one issue. It was not printing all the given values.
Code:
awk -F"|" '{for(i=3;i<=NF;i++){print $1 "," $2 "," ++q "," $i >> "inclusion1"};q=""}'   Input_file

The output for the above command:
Code:
OL,10031,1,Day
OL,10031,2,Black
OL,10031,3,Midi
OL,10031,4,Good
OL,10031,5,Value
OL,10031,6,P01
OL,10031,7,P07
OL,10031,1,Day
OL,10031,2,Black
OL,10031,3,Short
OL,10031,4,Good
OL,10031,5,Value
OL,10031,6,P01
OL,10031,7,P07

Hello rahulsk,

I am not sure I got your point here, following is the output mentioned by user(for a single line):
Code:
OL,10031,1,Day
OL,10031,2,Black
OL,10031,3,Midi
OL,10031,4,Good
OL,10031,5,Value

After running my code as follows is the output for all lines:
Code:
while read line; do echo $line | awk -F"|" '{for(i=3;i<=7;i++){print $1 "," $2 "," ++q "," $i};q=""}'; done < "Input_file"

Output of above code is as follows:
Code:
OL,10031,1,Day
OL,10031,2,Black
OL,10031,3,Midi
OL,10031,4,Good
OL,10031,5,Value
OL,10031,1,Day
OL,10031,2,Black
OL,10031,3,Short
OL,10031,4,Good
OL,10031,5,Value

I think code is providing the output similar to what OP has requested. Your opinions are welcomed in case I missed anything here, thank you.

Thanks,
R. Singh
# 9  
Old 11-15-2016
Hi All,

Many thanks for this quick help.
This is working and previous one was my mistake.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a sequence of numbers in a line for 1000 files

Hi, I try to explain my problem , I have a file like this: aasdsaffsc23 scdsfsddvf46567 mionome0001.pdb asdsdvcxvds dsfdvcvc2324w What I need to do is to create 1000 files in which myname line listing a sequence of numbers from 0001 to 1000. So I want to have : nomefile0001.txt that must... (10 Replies)
Discussion started by: danyz84
10 Replies

2. Shell Programming and Scripting

Need append sequence number

Hi, Need to add sequnce number to one of the csv file and please find below actual requirement. Input file ABC,500 XXQ,700 ADF,400, ART,200 Out put file should be 1,ABC,500 2,XXQ,700 3,ADF,400, 4,ART,200 (3 Replies)
Discussion started by: siva83
3 Replies

3. Shell Programming and Scripting

Hex number sequence help

Need some help doing this ... with awk maybe Input 0DF6 0DF7 0DF8 0DF9 0DFA 0DFB 0DFC 0DFD 0DFF 0E00 0E01 0E02 0E03 0E04 0E05 0E06 (11 Replies)
Discussion started by: greycells
11 Replies

4. 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

5. Shell Programming and Scripting

How to take the missing sequence Number?

Am using unix aix KSH... I have the files called MMRR0106.DAT MMRR0206.DAT MMRR0406.DAT MMRR0506.DAT MMRR0806.DAT .... ... MMRR3006.DAT MMRR0207.DAT These files are in one dircetory /venky ? I want the output like this ? Missing files are : MMRR0306.DAT MMRR0606.DAT... (7 Replies)
Discussion started by: Venkatesh1
7 Replies

6. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

7. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

8. 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

9. UNIX for Dummies Questions & Answers

creating sequence numbers in unix

Hi, Is there a way to create sequence numbers in unix i have a set of batches(which contain records) and i want to assign a number to every batch. how can i do that? (1 Reply)
Discussion started by: dnat
1 Replies

10. UNIX for Dummies Questions & Answers

sequence number checking

Hi there, I'm wanting to produce a shell script that will check through some file names and identify a skip in sequence (four digit seq num in file name). I have played on the idea of havng a file that has a sorted list of file names which I can read line at a time and cut out the sequence... (1 Reply)
Discussion started by: nhatch
1 Replies
Login or Register to Ask a Question