file index operation in loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file index operation in loop
# 1  
Old 10-17-2012
file index operation in loop

i have one file which contains data like the below


Code:
DE_CODE|AXXANY|APP_NAME|TELCO|LOC|NY
DE_CODE|AXXATX|APP_NAME|TELCO|LOC|TX
DE_CODE|AXXABT|APP_NAME|TELCO|LOC|BT
DE_CODE|AXXANJ|APP_NAME|TELCO|LOC|NJ
DE_CODE|AXXANJwt|APP_NAME|TELCO|LOC|WT

am going use a for loop or whole loop which will convert each line and process it.
could someone please help it

DE_CODE,APP_NAME and LOC are the hearder and AXXANY,TELCO and NY are data
i each looping am assigning the data like the below.

Code:
DE_CODE = AXXANY
APP_NAME= TELCO
LOC = NY

i want to a script to operate this. even the input line can extend futher after loc also in future.

Last edited by zaxxon; 10-17-2012 at 03:26 AM.. Reason: code tags
# 2  
Old 10-17-2012
One possibility:
Code:
# awk '{for (i=1;i<=NF;i++){if( !i % 2) {print $(i-1),$i}}}' FS='|' OFS=' = ' infile
DE_CODE = AXXANY
APP_NAME = TELCO
LOC = NY
DE_CODE = AXXATX
APP_NAME = TELCO
LOC = TX
DE_CODE = AXXABT
APP_NAME = TELCO
LOC = BT
DE_CODE = AXXANJ
APP_NAME = TELCO
LOC = NJ
DE_CODE = AXXANJwt
APP_NAME = TELCO
LOC = WT

# 3  
Old 10-17-2012
Slight modification/correction to Klashxx's solution to make it work with all awk implementations:
Code:
awk '{for (i=1;i<=NF;i++){if( !(i % 2)) {print $(i-1),$i}}}' FS='|' OFS=' = ' infile

# 4  
Old 10-17-2012
What's the difference to this https://www.unix.com/shell-programmin...#post302716569 thread?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

build array name based on loop index

Hi, I am new to perl and I have the following query please help here. I have following array variables declaration @pld1 = qw(00 01 02 03 04 05); @pld2 = qw(10 11 12 13 14 15); for(my $k=1;$k<=2;$k++) { //I want here to use @pld1 if $k is 1 // and @pld2 if $k is 2. How to do... (3 Replies)
Discussion started by: janavan
3 Replies

2. Shell Programming and Scripting

Arithmetic operation between columns using loop variable

Hi I have a file with 3 columns. say, infile: 1 50 68 34 3 23 23 4 56 ------- ------- I want to generate n files from this file using a loop so that 1st column in output file is (column1 of infile/(2*n+2.561)) I am doing like this: for ((i=1; i<=3; i++)) do a=`echo... (3 Replies)
Discussion started by: Surabhi_so_mh
3 Replies

3. Shell Programming and Scripting

Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ... (4 Replies)
Discussion started by: shashi792
4 Replies

4. Shell Programming and Scripting

dynamic index for array in while loop

Hi, I'm just trying to use a dynamic index for some array elements that I'm accessing within a loop. Specifically, I want to access an array at variable position $counter and then also at location $counter + 1 and $counter + 2 (the second and third array positions after it) but I keep getting... (0 Replies)
Discussion started by: weak_code-fu
0 Replies

5. Shell Programming and Scripting

Sort from start index and end index in line

Hi All, I have a file (FileNames.txt) which contains the following data in it. $ cat FileNames.txt MYFILE17XXX208Sep191307.csv MYFILE19XXX208Sep192124.csv MYFILE20XXX208Sep192418.csv MYFILE22XXX208Sep193234.csv MYFILE21XXX208Sep193018.csv MYFILE24XXX208Sep194053.csv... (5 Replies)
Discussion started by: krish_indus
5 Replies

6. Shell Programming and Scripting

How to access the elements of two arrays with a single loop using the inbuilt index.

Hi all, I wanted to access two arrays (of same size) using one for loop. Ex: #!/bin/bash declare -a num declare -a words num=(1 2 3 4 5 6 7) words=(one two three four five six seven) for num in ${num} do echo ":$num: :${words}:" done Required Output: :1: :one: (11 Replies)
Discussion started by: 14341
11 Replies

7. UNIX for Dummies Questions & Answers

wh inode index starts from 1 unlike array index (0)

brothers why inode index starts from 1 unlike array inex which starts from 0 its a question from the design of unix operating system of maurice j.bach i need to know the answer urgently...someone help please (1 Reply)
Discussion started by: sairamdevotee
1 Replies

8. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

9. Shell Programming and Scripting

Print out loop index on the console after executing each sybase DB query

Hello Guys, Well, using shell script, I'm doing loop on DB query as below: isql -Usa -Ptest -I /opt/sybase/interfaces << EOF use testdb go declare @i int select @i = 1 while(@i <= 5) begin Insert into TEST values (@i,"Test","TestDesc") select @i = @i + 1 end go EOF The Issue... (2 Replies)
Discussion started by: Alaeddin
2 Replies
Login or Register to Ask a Question