[Solved] Need to add Single quotes to particular lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Need to add Single quotes to particular lines
# 1  
Old 04-27-2012
[Solved] Need to add Single quotes to particular lines

Hi Guys,

I have the following file.

Code:
DbName=DBNAME
DbUser=USERID
DbPass=PASSLL
SrcLocation=/appl/data/VSTAR
SrcFile1=gmb_dly_ind_sls_20120410133424.txt
SrcFile2=
IpLocation=/appl/data/VSTAR/global_daily/input/GMB
IpFile=gmb_dly_ind_sls_20120410133424.txt
OutLocation=/appl/data/VSTAR/global_daily/output
OutFile1=GMB_D_Stg_IndSls_Ld_040.txt
OutFile2=GMB_D_Stg_IndSls_Ld_040.txt
BatchTrkId=323
BusinessUnit=GMB
Country=BRAZIL
CurrSlsDate=
PriorSlsDate=

I like to search for Country and BusinessUnit keyword and I like to add Single quotes(') after + and at the end.
The Output should be as below.

Code:
DbName=GMNGSRDB
DbUser=NGSRALL
DbPass=NGSRALL
SrcLocation=/appl/data/VSTAR
SrcFile1=gmb_dly_ind_sls_20120410133424.txt
SrcFile2=
IpLocation=/appl/data/VSTAR/global_daily/input/GMB
IpFile=gmb_dly_ind_sls_20120410133424.txt
OutLocation=/appl/data/VSTAR/global_daily/output
OutFile1=GMB_D_Stg_IndSls_Ld_040.txt
OutFile2=GMB_D_Stg_IndSls_Ld_040.txt
BatchTrkId=323
BusinessUnit='GMB'
Country='BRAZIL'
CurrSlsDate=
PriorSlsDate=

Please somebody help me out here..

Cheers!!!!
# 2  
Old 04-27-2012
Hi

Code:
awk -F"=" '/BusinessUnit|Country/{$2=q$2q}1' q="'" OFS="=" file

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 04-27-2012
Thanks guruprasdpr,,, I came up with this command.
Code:
awk -F'=' '/Country|BusinessUnit/{print $1 "=\x27" $2 "\x27" }'

But it was giving only those two records,, Can you tell me what i did wrong.

Cheers!!!!!
# 4  
Old 04-27-2012
Hi

Its displaying only those two because your filter is set for only those 2. Try this:

Code:
awk -F'=' '/Country|BusinessUnit/{print $1 "=\x27" $2 "\x27";next}1' file

The '1' makes every line to get printed by default. The 'next' is to prevent those filtered lines from getting printed again by the '1'.

Guru.
# 5  
Old 04-27-2012
Thanks for that explanation Smilie
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 add line breaks to perl command with large text in single quotes?

Below code extracts multiple field values from XML into array and prints all in one line. perl -nle '@r=/(?: jndiName| authDataAlias| value| minConnections| maxConnections| connectionTimeout| name)="(+)/g and print join ",",$ENV{tIPnSCOPE},$ENV{pr ovider},$ENV{impClassName},@r' server.xml ... (4 Replies)
Discussion started by: kchinnam
4 Replies

2. UNIX for Dummies Questions & Answers

[Solved] How to extract single and duplicate lines from file?

Hi, I need help! I have two files, one containing a list of codes and the other a list of codes and their meaning. I need to extract from file 2 all the codes from file 1 into a new file. These are my files: File1: Metbo Metbo Memar Mth Metbo File2: Metbo Methanoculleus... (3 Replies)
Discussion started by: Lokaps
3 Replies

3. Shell Programming and Scripting

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

4. Shell Programming and Scripting

Having a terrible problem with quotes/single quotes!

Hello. I'm trying to write a bash script that uses GNU screen and have hit a brick wall that has cost me many hours... (I'm sure it has something to do with quoting/globbing, which is why I post it here) I can make a script that does the following just fine: test.sh: #!/bin/bash # make... (2 Replies)
Discussion started by: jondecker76
2 Replies

5. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

6. UNIX for Dummies Questions & Answers

grep single quotes or double quotes

Unix superusers, I am new to unix but would like to learn more about grep. I am very familiar with regular expressions as i have used them for searching text files in windows based text editors. Since I am not very familiar with Unix, I dont understand when one should use GREP with the... (2 Replies)
Discussion started by: george_vandelet
2 Replies

7. Shell Programming and Scripting

Single quotes and double quotes

Hi guys, I have a sed line in double quotes which works fine, but I want it to be in single quotes here is the sed line sed "/abc_def/s/\'.*\'/\'\${abc_def}\'/" can some one give the equivalent to the above script in single quotes Thanks a ton (5 Replies)
Discussion started by: sol_nov
5 Replies

8. Shell Programming and Scripting

Add two lines in a single string

Dear All, I want to add two lines in single string. Example: String1: God Bless You. String2: Thank You. Now i want to store these two above lines into a single string(str) and when i will echo it, it should be like > echo $str God Bless You. Thank You. Please help me. Thanks in... (1 Reply)
Discussion started by: umesh.rout
1 Replies

9. UNIX for Dummies Questions & Answers

Add single quotes in string

Hi All, I love this site, it helps newbie people like me and I appreciate everyone's help! Here is my questions. I am trying to concatenate a single quote into a character/string from a text file for each line (lets say ABC should look like 'ABC'). I tried to use awk print command to do... (1 Reply)
Discussion started by: mrjunsy
1 Replies

10. Shell Programming and Scripting

Double quotes or single quotes when using ssh?

I'm not very familiar with the ssh command. When I tried to set a variable and then echo its value on a remote machine via ssh, I found a problem. For example, $ ITSME=itsme $ ssh xxx.xxxx.xxx.xxx "ITSME=itsyou; echo $ITSME" itsme $ ssh xxx.xxxx.xxx.xxx 'ITSME=itsyou; echo $ITSME' itsyou $... (3 Replies)
Discussion started by: password636
3 Replies
Login or Register to Ask a Question