Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help modify last character in last line 1

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
Using BladeLogic NSH (Simliar to ZSH)...

System Variables:
x=myserver
y=myfile

Code:
awk 'BEGIN{OFS=","}{if (NR < 2) print "\042""'"$x"'""\042","\042""'"$y"'""\042","\042"$0; else print $0}END{print "\042"" ^ENDOFRECORD^"}' //${x}//usr/openv/netbackup/${y} >> //myserver/tmp/inprogress/exclude.final

contents of myfile:
cat
dog
bunny

Desired output:

"myserver","myfile","cat
dog
bunny" ^ENDOFRECORD^

This is what I'm getting:

"myserver","myfile","cat
dog
bunny
" ^ENDOFRECORD^
 
Try this solution, using printf which doesn't automatically add line feeds:

Code:
awk -v x=[blue]$x[/blue] -v y=[blue]$y[/blue] '
        [green]BEGIN[/green]{[blue]OFS[/blue]=[red]"[/red][purple],[/purple][red]"[/red]}
        {
                [olive]if[/olive] ([blue]NR[/blue] < 2)
                        [b]printf[/b]([red]"[/red][purple]\"%s\",\"%s\",\"%s[/purple][red]"[/red],x,y,[blue]$0[/blue])
                [olive]else[/olive]
                        [b]printf[/b]([red]"[/red][purple]\n%s[/purple][red]"[/red],[blue]$0[/blue])
        }
        [green]END[/green] { [b]print[/b] [red]"[/red][purple]\" ^ENDOFRECORD^[/purple][red]"[/red] }
' //${x}//usr/openv/netbackup/${y} >> //myserver/tmp/inprogress/exclude.final

I also assigned the shell variables to awk variables to reduce the amount of quote hell...


Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top