- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Awk Help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2003 11:02 AM
01-28-2003 11:02 AM
I am having file containing numbers
23654
234444
23444
I want the output like below,
insert '23654'
insert '234444'
insert '23444'
In short, how can i print ' in awk.
Thanks in adv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2003 11:03 AM
01-28-2003 11:03 AM
Re: Awk Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2003 11:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2003 11:20 AM
01-28-2003 11:20 AM
Re: Awk Help
Or with shell script:
while read a
do
echo "insert '"$a"'"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2003 11:23 AM
01-28-2003 11:23 AM
Re: Awk Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2003 11:24 AM
01-28-2003 11:24 AM
Re: Awk Help
This works:
awk ' { printf "\x027insert\x027%s\n",$0 } ' inputfilename
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 01:26 AM
01-29-2003 01:26 AM
Re: Awk Help
l1:/tmp 102 > cat > xx
23654
234444
23444
l1:/tmp 103 > sed "s/.*/insert '&1'/" xx
insert '236541'
insert '2344441'
insert '234441'
l1:/tmp 104 >
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 03:10 AM
01-29-2003 03:10 AM
Re: Awk Help
it should be :
sed "s/.*/insert \'&\'/"
because &1 append a '1' on each line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 04:14 AM
01-29-2003 04:14 AM
Re: Awk Help
John,
I'm not sure the author will reply back.
Carlos,
You're right, I mangled the sed, here's one that works (and I took Procura's advice and removed the escaping of the apost's):
sed "s/\(.*\)/insert '\1'/" filename
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 07:37 PM
01-29-2003 07:37 PM
Re: Awk Help
Extremly sorry for delay.
If have two field like below
293874 239487
239478 239487
----------
i want output as using "SED" or AWK
'293874' , '239487'
'239478' , '239487'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 10:24 PM
01-29-2003 10:24 PM
Re: Awk Help
echo "this is the trick" | awk '{printf("'\''%s'\''\n",$0)}'
in your case:
# cat inputfile
293874 239487
239478 239487
# awk '{printf("'\''%s'\'','\''%s'\''\n",$1,$2)}' inputfile
'293874','239487'
'239478','239487'
very clear, isn't it? ;-)
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 10:28 PM
01-29-2003 10:28 PM
Re: Awk Help
quote-backslash-quote-quote to print ' in awk
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2003 12:31 AM
01-30-2003 12:31 AM
Re: Awk Help
Here's some obfuscated examples:
l1:/tmp 121 > cat file
12345
23456 78901
34567 89012 62534
45678 90123 72635 91827
l1:/tmp 122 > perl -ple '$"=",";$_=qq{@{[map{qq{\x27$_\x27}}split/\D+/]}}' file
'12345'
'23456','78901'
'34567','89012','62534'
'45678','90123','72635','91827'
l1:/tmp 123 > perl -nle 'print+v39,join(v39.44.39,split/\D+/),v39' file
'12345'
'23456','78901'
'34567','89012','62534'
'45678','90123','72635','91827'
l1:/tmp 124 >
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2003 06:54 AM
01-30-2003 06:54 AM
Re: Awk Help
Works like this:
(1) The first "-e"
-e "s/$/ /"
Appends a space to the end of the line (so the next test will always work - hacking)
(2) the second "-e"
-e "s/\([0-9]*\)[[:space:]]/'\1',/g"
Says match all number groups (numbers seperated by spaces, then wrap them with apost's and a comma)
(3) the third "-e"
-e "s/'',//g"
removes any BOGUS '', stuff
(4) the forth "-e"
-e "s/',$/'/"
Removes other BOGUS ', at the end of the line
live free or die
harry