Need to append at end


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to append at end
# 1  
Old 03-09-2010
Wrench Need to append at end

I have the following input
Code:
axrsgpar0335                                                     METTEST           DPC  OUTLN                          OPEN                             Y 
axrsgpar0335                                                     METTEST           DPC  SYS                            OPEN                             N 
axrsgpar0335                                                     METTEST           DPC  SYSTEM                         OPEN                             Y 
axrsgpar0335                                                     METTEST           DPC  SAM                            OPEN                             N 
axrsgpar0335                                                     METTEST           DPC  DIP                            LOCKED                           N 
axrsgpar0335                                                     METTEST           PPC  DIP                            LOCKED                           N 
axrsgpar0335                                                     METTEST           PPC  HIT                            OPEN                             N

I am using the following command to get this desired o/p

Code:
sed "s/ \& /_\&_/" /u00/app/oracle/admin/logs/Flatfile.lst | awk '{OFS=",";print $1,$2,$3,$4,$5,$6}' | tr "_" " "

axrsgpar0335,METTEST,DPC,OUTLN,OPEN,Y 
axrsgpar0335,METTEST,DPC,SYS,OPEN,N 
axrsgpar0335,METTEST,DPC,SYSTEM,OPEN,Y 
axrsgpar0335,METTEST,DPC,SAM,OPEN,N 
axrsgpar0335,METTEST,DPC,DIP,LOCKED,N 
axrsgpar0335,METTEST,PPC,DIP,LOCKED,N 
axrsgpar0335,METTEST,PPC,HIT,OPEN,N

But i have another variable $EAI and $APPLN in my script i need to append that at end, I tried this command but am getting the following o/p

Code:
sed "s/ \& /_\&_/" /u00/app/oracle/admin/logs/Flatfile.lst | awk '{OFS=",";print $1,$2,$3,$4,$5,$6,"$EAI","$APPLN"}' | tr "_" " "
 
axrsgpar0335,METTEST,DPC,OUTLN,OPEN,Y,$EAI,$APPLN
axrsgpar0335,METTEST,DPC,SYS,OPEN,N,$EAI,$APPLN
axrsgpar0335,METTEST,DPC,SYSTEM,OPEN,Y,$EAI,$APPLN 
axrsgpar0335,METTEST,DPC,SAM,OPEN,N,$EAI,$APPLN 
axrsgpar0335,METTEST,DPC,DIP,LOCKED,N,$EAI,$APPLN 
axrsgpar0335,METTEST,PPC,DIP,LOCKED,N,$EAI,$APPLN 
axrsgpar0335,METTEST,PPC,HIT,OPEN,N,$EAI,$APPLN

I want the value to substituted instead of $EAI and $APPLN.

Help me

Gopal

Last edited by pludi; 03-09-2010 at 06:26 AM.. Reason: code tags, please...
# 2  
Old 03-09-2010
Code:
sed 's/ $//g' filename | awk -v eai=$EAI -v app=$APPLN 'BEGIN{OFS=","}{gsub(/ /,",");print $0,eai,app}'


cheers,
Devaraj Takhellambam
# 3  
Old 03-09-2010
Just awk Smilie
Code:
awk -v v="$EAI,$APPLN" 'NF{$1=$1;$0=$0 OFS v}1' OFS="," infile


Last edited by danmero; 03-09-2010 at 12:23 PM.. Reason: Add NF, don't process empty lines.
# 4  
Old 03-09-2010
I want one single command

Hi
Thanks for all your replies. Awesome. But can include those substitution in my present command something like this,

Code:
sed "s/ \& /_\&_/" /u00/app/oracle/admin/logs/Flatfile.lst | awk -v eai=$EAI -v app=$APPLN '{OFS=",";print $1,$2,$3,$4,$5,$6,EAI,APPLN}' | tr "_" " "

Will the above command work?

---------- Post updated at 01:15 PM ---------- Previous update was at 07:20 AM ----------

Code:
sed "s/ \& /_\&_/" /u00/app/oracle/admin/logs/Flatfile.lst | awk -v eai="$EAI,$APPLN" '{OFS=",";print $1,$2,$3,$4,$5,$6,EAI,APPLN}' | tr "_" " "

Thank you so much...Smilie

Last edited by Scott; 03-09-2010 at 04:10 PM.. Reason: Code tags please...
# 5  
Old 03-10-2010
Try:

Code:
perl -lane '$,=",";print (@F,'$EAI','$APPLN')'  file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to append in the beginning not at the end?

Hi, I now that >> will append text to the end of the text that is already inside the file. How to append the new text infront of the text that is already in the file. Thanks for any input. Regards, Chandu (3 Replies)
Discussion started by: chandrakanth
3 Replies

2. Shell Programming and Scripting

Append Pipes at the end of each line

Hi , I have pipe delimited file containing 12 columns having below data in AIX Input : A|B|C|D|E|F|G|H|I|J|K|L^M A1|B1|C1|D1|E1^M A2|B2|C2^M So in first row i have 11 pipes which is fine. In second row I have 4 pipes, so additional 7 pipes should get append In third row I have 2... (3 Replies)
Discussion started by: sonu_pal
3 Replies

3. Shell Programming and Scripting

append | to the end of each data in a file

I have a file which has data in the below format: 7810902|6783014102| || |0| |0| |0| |0|||||T|04/13/2006||9423|7421||100|2006-04-13 16:50:28|||2006-04-13 16:50:28|n|51|-1||214 1089929|||||NewSpCreateAction request successful. Activity ID = <826528>||||100|n|2006-04-13 16:50:27|2006-04-13... (3 Replies)
Discussion started by: ankianand88
3 Replies

4. UNIX for Dummies Questions & Answers

Append characters to end of line

Coding in unix shell script. Hi All, Please help Thanks (6 Replies)
Discussion started by: sam12345
6 Replies

5. Shell Programming and Scripting

append end of line with 8 spaces

child_amt=$amount prev_line="$prev_line $child_amt" i am getting the result like this 21234567890001343 000001004OLFXXX029100020091112 0000060 but i want 8 spaces between the eg: 21234567890001343 000001004OLFXXX029100020091112 0000060 how can i do this in .ksh (1 Reply)
Discussion started by: kshuser
1 Replies

6. Shell Programming and Scripting

how to append the pattern at the end of the line

-Hi I have multiple files which contain a line with the word "exec". I need to add the following pattern " -cmode -ccheap" on the same line where "exec" is at the end. Any idea? Thanks a lot in advance to everybody... -A (2 Replies)
Discussion started by: aoussenko
2 Replies

7. Shell Programming and Scripting

Append newline at the file end

Hi All, Is there any way to append a newline character at the end of a file(coma-separated file), through shell script? I need to check whether newline character exists at the end of a file, if it does not then append it. Regards, Krishna (1 Reply)
Discussion started by: KrishnaSaran
1 Replies

8. Shell Programming and Scripting

How to append words at the end of first line

Hi Unix gurus This is my first post here. I have a file which looks like this: string1,string2 ,string3 ,string4 ... ... I need to append all words below first line to the first line, ie string1,string2,string3,string4,... Bear in mind that it is not known how many lines follow... (11 Replies)
Discussion started by: lmatlebyane
11 Replies

9. Shell Programming and Scripting

to append few chars at the end of a file

hi i want to open a file at runtime append few chars at the end of each line all these i want to have done automatically how to do it (2 Replies)
Discussion started by: trichyselva
2 Replies

10. Shell Programming and Scripting

echo, append to end of file

I need the line printed with echo to append to eof of to exactly line, am i able to do that? i mean echo "sysctl -w lalala=1" > to end of file /etc/sysctl.conf or to the 21st line, if the line exist, open new line and insert text there. Thx.maybe i'm in wrong topic but anyway... (2 Replies)
Discussion started by: hachik
2 Replies
Login or Register to Ask a Question