Append test as a row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append test as a row
# 8  
Old 09-14-2011
I modified the MSMARIO script and achieved some what...


Code:
for i  in `cat input.txt | awk '{print $3 "=" $6}'`
 do
x=`echo $i | cut -d "=" -f 1`
y=`echo $i | cut -d "=" -f 2`
r="";
if [ $x =  "A" ]; then
a=$y;
if [ $a = "" ];
then
a= `echo " "`
fi
elif [ $x = "B" ]; then
b=`echo ",$y"`
if [ $b = "" ];
then
b=`echo " ,"`
fi
elif [ $x = "C" ]; then
c=`echo ",$y"`
if [ $c = "" ];
then
c=`echo " ,"`
fi
elif [ $x = "D" ]; then
d=`echo ",$y"`
if [ $d = "" ];
then
d=`echo " ,"`
fi
echo $a$b$c$d;
fi
done

I tried using one liner command with help of ssed/swk but couldn't able to do ... if any got better idea plz throw a input
# 9  
Old 09-14-2011
Quote:
Originally Posted by greenworld123

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.

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

here is my result
Code:
debian:/home/mario# ./test
0,2,3
0,2,4
0, ,3
 ,0,3

This User Gave Thanks to MSMario For This Post:
# 10  
Old 09-14-2011
Try this...

Code:
awk 'BEGIN{i=1}!/setting field value/{next}{if($(NF-1)=="A"){a[i]=$NF;getline}
if($(NF-1)=="B"){b[i]=$NF;getline} if($(NF-1)=="C"){c[i]=$NF;getline}}{i++}
END{print "A,B,C";for(j=1;j<i;j++){print a[j]","b[j]","c[j]}}' inputFile

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

--ahamed
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