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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

solved - lowercase between quotes "xxx" 1

Status
Not open for further replies.

jwzumwalt

Technical User
Jun 4, 2023
2
0
0
US
I am using a awk command that changes text between quotes to lower case by using the field separator at the quotes.

Code:
awk 'BEGIN { FS = "\"" }  {print ($1)tolower($2)$3} ' test.txt > temp

Unfortunately this command also removes the quotes "" from the output.
How can I get awk to keep/replace the original quotes?

Thanks for the help :)
 
Hi

[ul]
[li]There you concatenated the 3 field. [tt]print[/tt] then out as separate fields. I mean, put comma ( [tt],[/tt] ) between them, so they get output with output field separator between them.[/li]
[li]If you not want to change the separators, set the [tt]OFS[/tt] ( output field separator ) to the same as [tt]FS[/tt] ( field separator )[/li]
[/ul]
Code:
awk '[b]BEGIN[/b] [teal]{[/teal] FS [teal]=[/teal] OFS [teal]=[/teal] [i][green]"[/green][/i][lime]\"[/lime][i][green]"[/green][/i] [teal]}  {[/teal][b]print[/b] [navy]$1[/navy][teal],[/teal] [b]tolower[/b][teal]([/teal][navy]$2[/navy][teal]),[/teal] [navy]$3[/navy][teal]}[/teal]'

Feherke.
feherke.github.io
 
Thanks feherke, Your explanation was easy to understand and will help me in the future!
I only have the occasion to use sed or awk once or twice a year and nearly
always use a cut/paste/modify of someone else's snippet; as was the case here.

I always save my scripts and any explanations I find. So, your comment will be added to
my 20 or so sed and awk scripts. I have over 7,000 bash scripts, if that is any
indicator of how little I use sed & awk! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top