Append test as a row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append test as a row
# 1  
Old 09-09-2011
Append test as a row

I searched the thread i couldn't able to find the solution that's y posted here.. help me

i have a file as

Code:
setting field value A 0 
setting field value B 2
setting field value C 3
some text
------
---
some text
setting field value A 0 
setting field value B 2
setting field value C 4
some text
------
---
some text
setting field value A 0 
setting field value C 3
some text
------
---
some text
setting field value B 0 
setting field value C 3

i need output as

Code:
A, B, C
0, 2,3
0,2,4
0,,3
,0,3


Last edited by vbe; 09-13-2011 at 11:45 AM.. Reason: typos
# 2  
Old 09-09-2011
A, B, C will this change at a later point?
I mean will it extend to D E etc?

--ahamed
# 3  
Old 09-09-2011
And is it important to have columns A, B, C in the order or it may be in an arbitrary order, like B, C, A, D (with the right following rows, of course)?
# 4  
Old 09-09-2011
You'll have to provide more data from the actual file.

--ahamed
# 5  
Old 09-09-2011
Here it is Smilie
Code:
for i in `cat tekst | grep value | awk '{print $4 "=" $5}'`
do
    x=`echo $i | cut -d "=" -f 1`
    y=`echo $i | cut -d "=" -f 2`

    if [ $x == "A" ]; then
        t=$[t+1];
        a=$y;
    elif [ $x == "B" ]; then
        t=$[t+3];
        b=$y;
    elif [ $x == "C" ]; then
        t=$[t+5];
        c=$y;
        if [ $t -eq 9 ]; then
            echo $a,$b,$c
        elif [ $t -eq 1 ]; then
            echo $a, ,
        elif [ $t -eq 6 ]; then
            echo $a, ,$c
        elif [ $t -eq 8 ]; then
            echo ' ',$b,$c
        fi
        t=0;
    fi

done

with viariable t you have to make all possibilites with missing one ore two
# 6  
Old 09-13-2011
Quote:
Originally Posted by ahamed101
You'll have to provide more data from the actual file.

--ahamed
Sorry for the late reply....

It will have only till A,B,C .... it wn't increase to D,E.... but
some time any one or two might not be their ... those cases has to be left as empty.

---------- Post updated at 09:23 AM ---------- Previous update was at 09:23 AM ----------

Quote:
Originally Posted by yazu
And is it important to have columns A, B, C in the order or it may be in an arbitrary order, like B, C, A, D (with the right following rows, of course)?
i need to export that to excel .. so that should be in order as A,B,C

---------- Post updated at 09:36 AM ---------- Previous update was at 09:23 AM ----------

Quote:
Originally Posted by MSMario
Here it is Smilie
Code:
for i in `cat tekst | grep value | awk '{print $4 "=" $5}'`
do
    x=`echo $i | cut -d "=" -f 1`
    y=`echo $i | cut -d "=" -f 2`
 
    if [ $x == "A" ]; then
        t=$[t+1];
        a=$y;
    elif [ $x == "B" ]; then
        t=$[t+3];
        b=$y;
    elif [ $x == "C" ]; then
        t=$[t+5];
        c=$y;
        if [ $t -eq 9 ]; then
            echo $a,$b,$c
        elif [ $t -eq 1 ]; then
            echo $a, ,
        elif [ $t -eq 6 ]; then
            echo $a, ,$c
        elif [ $t -eq 8 ]; then
            echo ' ',$b,$c
        fi
        t=0;
    fi
 
done

with viariable t you have to make all possibilites with missing one ore two
script is giving a error in

Code:
if [ $x == "A" ]; then
        t=$[t+1];
        a=$y;
    elif [ $x == "B" ]; then
        t=$[t+3];
        b=$y;
    elif [ $x == "C" ]; then

Below is the error i am getting
Code:
./test2.ksh[5]: ==: A test command parameter is not valid.
./test2.ksh[8]: ==: A test command parameter is not valid.
./test2.ksh[11]: ==: A test command parameter is not valid.

---------- Post updated at 09:55 AM ---------- Previous update was at 09:36 AM ----------

I tried with 'Sed' but i couldn't able to find proper command...
Help with the simple and command options
# 7  
Old 09-13-2011
Code:
#!/usr/bin/ksh
mA=''
mB=''
sed -n 's/^setting field value //p' Inp_File |
while read mTag mValue; do
  if [[ "${mTag}" = "A" ]]; then
    if [[ "${mA}" != "" || "${mB}" != "" ]]; then
      echo "${mA},${mB},"
      mB=''
    fi
    mA=${mValue}
  else
    if [[ "${mTag}" = "B" ]]; then
      if [[ "${mB}" != "" ]]; then
        echo "${mA},${mB},"
        mA=''
      fi
      mB=${mValue}
    else
      echo "${mA},${mB},${mValue}"
      mA=''
      mB=''
    fi
  fi
done
if [[ "${mA}" != "" || "${mB}" != "" ]]; then
  echo "${mA},${mB},"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

2. Shell Programming and Scripting

Add Row from First Row (Split Row)

HI Guys, I have Below Input :- RepigA_hteis522 ReptCfiEtrBsCll_aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 RepigA ReptCfiEtrBsCll hteis522 aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 Split Data in two first row... (2 Replies)
Discussion started by: pareshkp
2 Replies

3. Shell Programming and Scripting

Read line from the file and append it to each row

Hi All, We have a file in the following format: 0.010000 $ ITI 11 LV2 $ 40456211 $ 0.135000 $ ITI 11 LV1 $ 40512211 $ 1.215600 $ ITI 11 ITI3 $ 41406211 $ 24/05/2014 14:05:02 0.030000 $ ITI 11 LV2 $ 40456211 $ ... (3 Replies)
Discussion started by: gauravsinghal79
3 Replies

4. Shell Programming and Scripting

Test command:Duplicate Header row in Log File

I have a script that is inventorying (not sure if thats a word) my environment. It goes out and pulls Hostname OS, IP, and ENV (dev, prod, etc)..then spits all that to a logfile At the top of my script i have a check to see if the logfile exist. ] || touch $LOGFILE && echo "ENV" "\t"... (3 Replies)
Discussion started by: nitrobass24
3 Replies

5. UNIX for Dummies Questions & Answers

append column and row header to a file in awk script.

Hi! Is there a way to append column and row header to a file in awk script. For example if I have Jane F 39 manager Carlos M 40 system administrator Sam F 20 programmer and I want it to be # name gend age occup 1 Jane F 39 manager 2 Carlos M ... (4 Replies)
Discussion started by: FUTURE_EINSTEIN
4 Replies

6. Shell Programming and Scripting

Append data to new row in CSV file every day

Hi All I will run the same script every day in corn and output should go to same CSV file but in different row with dates on it. Below is my example in attached format. Script i am using to collect switch port online DATE=`date '+%d-%m-%y'` for f in `cat... (1 Reply)
Discussion started by: ranjancom2000
1 Replies

7. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

8. Shell Programming and Scripting

Append Second Row to First Row @ end in a file

Hi I want to append line 2n to 2n-1 line where n=1...LastLine in my file. eg: Actual File: Hello Everyone Welcome TO Unix I need Your help Required File: HelloEveryone WelcomeTO Unix I needYour help (5 Replies)
Discussion started by: dashing201
5 Replies

9. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

10. Shell Programming and Scripting

to append data in a single row

Hi all, I need a logic in UNIX to append contents of a file in same row, where the original contents are found one below the other. For example. My i/p file contains: “user1”,”employee1”,”04/28/2009” “5678” “78” “user2”,”employee2”,”04/30/2009” I want my output... (8 Replies)
Discussion started by: Sgiri1
8 Replies
Login or Register to Ask a Question