03-11-2008
awk to print ' (single quotes)
I'm building a file with sql delete statements. I need to print the single quotes for the where clause.
i.e.
delete from Command where CommandName = 'SomeName';
I have the following in my script
input=$(pwd)/Cmnd.csv
i=0
while read line
do
if test $i -ge 1;
then
echo "$line" | awk -F'|' '{print "delete from Command where CommandName='"$1"';}' >> deleteCmd.dat
fi
i=$i+1
done < $input
This gives me:
delete from Command where CommandName=;
how do I print the (single quotes) ' with awk?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have written a code to modify a string say,
StringA=abc,def,ghi
I need to change it to something like:
StringB=This means abc='ABC', This mean def='DEF', This means ghi= 'GHI'
StringB=$(echo $StringA | awk -F',' 'BEGIN { OFS="," } { for (i=1; i<=NF;i++) $i="This means... (2 Replies)
Discussion started by: tostay2003
2 Replies
2. Shell Programming and Scripting
Hi,
I am trying to write the following command as an alias in my .bashrc file.
bjobs -u all | awk '{if (NR > 1) {username++;}}END{{print"\nJOBS BY USER:\n"} for (i in username) {print username,i;}{print"\n Total Jobs=",NR-1,"\n" }}'
The command simply puts how many jobs each user is... (2 Replies)
Discussion started by: jacekmaciek
2 Replies
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
How can I use single quotes as field separator in awk? (1 Reply)
Discussion started by: locoroco
1 Replies
5. UNIX for Dummies Questions & Answers
Hi i have to insert the below line into a specific line number of another file
export MBR_CNT_PRCP_TYPE_CODES_DEL="'01','02','04','05','49','55','UNK'"
I have passed the above line to a variable say ins_line. I have used below command to perform the insert
awk 'NR==3{print "'"${ins_line}"'"}1'... (1 Reply)
Discussion started by: sathishteradata
1 Replies
6. Shell Programming and Scripting
How do I use single quotes as record separator in awk?
I just couldn't figure that out. I know how to use single quotes as field separator, and double quotes as both field and record separator ... (1 Reply)
Discussion started by: locoroco
1 Replies
7. Shell Programming and Scripting
# echo 'export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk '{print \$1}')' >> new_file
#
# cat new_file
export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk {print $1})
#
Now how to echo the quotes around the... (2 Replies)
Discussion started by: proactiveaditya
2 Replies
8. Shell Programming and Scripting
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
9. Shell Programming and Scripting
Hi All,
I have input data like follows:
"1234"|"ABC"
"1234"|"CBA"
"1222"|"ZZZ"
I am trying to awk print all records where Col1 = "1234".
Below is the code I have so far:
Var1=1
Var2=1234
awk -F "|" "$ ${Var1} == "\"${Var2}\"" { print; }' inputfile
However when the AWK... (2 Replies)
Discussion started by: RichZR
2 Replies
10. Shell Programming and Scripting
Hi,
Need help, using awk command to insert statement
awk -v q="'" '{ print "db2 connect to repolab > /dev/null; " "\n" "db2 -x \" select name from IBMPDQ.PROFILE where managed_database = " q $1"_"$3"__0" q "\"" } ' profile.txt | sh - | awk -v i="'" ' { print "db2 connect to repolab >... (1 Reply)
Discussion started by: Mathew_paul
1 Replies
LEARN ABOUT SUSE
io::atomicfile
IO::AtomicFile(3) User Contributed Perl Documentation IO::AtomicFile(3)
NAME
IO::AtomicFile - write a file which is updated atomically
SYNOPSIS
use IO::AtomicFile;
### Write a temp file, and have it install itself when closed:
my $FH = IO::AtomicFile->open("bar.dat", "w");
print $FH "Hello!
";
$FH->close || die "couldn't install atomic file: $!";
### Write a temp file, but delete it before it gets installed:
my $FH = IO::AtomicFile->open("bar.dat", "w");
print $FH "Hello!
";
$FH->delete;
### Write a temp file, but neither install it nor delete it:
my $FH = IO::AtomicFile->open("bar.dat", "w");
print $FH "Hello!
";
$FH->detach;
DESCRIPTION
This module is intended for people who need to update files reliably in the face of unexpected program termination.
For example, you generally don't want to be halfway in the middle of writing /etc/passwd and have your program terminate! Even the act of
writing a single scalar to a filehandle is not atomic.
But this module gives you true atomic updates, via rename(). When you open a file /foo/bar.dat via this module, you are actually opening a
temporary file /foo/bar.dat..TMP, and writing your output there. The act of closing this file (either explicitly via close(), or
implicitly via the destruction of the object) will cause rename() to be called... therefore, from the point of view of the outside world,
the file's contents are updated in a single time quantum.
To ensure that problems do not go undetected, the "close" method done by the destructor will raise a fatal exception if the rename() fails.
The explicit close() just returns undef.
You can also decide at any point to trash the file you've been building.
AUTHOR
Primary Maintainer
David F. Skoll (dfs@roaringpenguin.com).
Original Author
Eryq (eryq@zeegee.com). President, ZeeGee Software Inc (http://www.zeegee.com).
REVISION
$Revision: 1.2 $
perl v5.12.1 2005-02-10 IO::AtomicFile(3)