- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk or perl to place 'around word'
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
11-29-2005 07:06 AM
11-29-2005 07:06 AM
I need to surround the field by ' ', so it can be inserted into the database.
Also if I could, do a unique on the file and only pull the one instance of the file.
File
SLAMTIDSQL 345 TEST SQL LOAD
TIDDLAMSQL 678 TEST SQL LOAD
TESTIDSQL1 111 TESTING LOAD
LAURATEST1 188 HOME
TIDSLAMSQL 678 TEST SQL LOAD
LAURATEST1 188 HOME
Need to be like:
'SLAMTIDSQL','345 TEST SQL LOAD'
'TIDDLAMSQL','678 TEST SQL LOAD'
'TESTIDSQL1','111 TESTING LOAD'
'LAURATEST1','188 HOME'
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 07:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 07:36 AM
11-29-2005 07:36 AM
Re: awk or perl to place 'around word'
To do this , you can take help of vi.
1. use vi to add ' at both end.
:%s/^/'/g
:%s/$/'/g
save the file in diff name. say aa
2. cut the first column to a diff file. aa.1
# cat aa | awk '{print $1}' > aa.1
3. vi aa.1
:%s/$/','/g
4. # cat aa | awk '{print $2 , $3 , $4 , $5}' > aa.2
5. # paste aa.1 aa.2 > aa.final
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 07:38 AM
11-29-2005 07:38 AM
Re: awk or perl to place 'around word'
----------------------
{
printf("'%s','",$1)
i = 2
while (i < NF)
{
printf("%s ",$(i))
++i
}
printf("%s'\n",$(i))
}
----------------------------
awk -f my.awk infile > outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 07:40 AM
11-29-2005 07:40 AM
Re: awk or perl to place 'around word'
Given the perl script 'perl.pl':
# cat perl.pl
#!/usr/bin/perl
while (<>) {
@flds = split /\s+/;
print "'$flds[0]','@flds[1..$#flds]'\n";
}
Now, do:
./perl.pl yourfile|sort -u
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 07:43 AM
11-29-2005 07:43 AM
Re: awk or perl to place 'around word'
sort -u filename > newfile
ex newfile <
1,\$s/$/'/
1,\$s/ /','/
wq!
EOD
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 07:45 AM
11-29-2005 07:45 AM
Re: awk or perl to place 'around word'
the simple and slow approach:
#!/usr/bin/sh
cat infile | while read a b
do
echo \'$a\',\'$b\' >>path_to_outfile
done
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 09:51 AM
11-29-2005 09:51 AM
Re: awk or perl to place 'around word'
# perl -ple'chomp;$_=join",",map{"\47$_\47"}split/\t/,$_,-1' file
a5:/tmp 115 > cat file
SLAMTIDSQL 345 TEST SQL LOAD
TIDDLAMSQL 678 TEST SQL LOAD
TESTIDSQL1 111 TESTING LOAD
LAURATEST1 188 HOME
TIDSLAMSQL 678 TEST SQL LOAD
LAURATEST1 188 HOME
a5:/tmp 116 > cat -vet file SLAMTIDSQL^I345 TEST SQL LOAD$
TIDDLAMSQL^I678 TEST SQL LOAD$
TESTIDSQL1^I111 TESTING LOAD$
LAURATEST1^I188 HOME$
TIDSLAMSQL^I678 TEST SQL LOAD$
LAURATEST1^I188 HOME$
a5:/tmp 117 > perl -ple'chomp;$_=join",",map{"\47$_\47"}split/\t/,$_,-1' file
'SLAMTIDSQL','345 TEST SQL LOAD'
'TIDDLAMSQL','678 TEST SQL LOAD'
'TESTIDSQL1','111 TESTING LOAD'
'LAURATEST1','188 HOME'
'TIDSLAMSQL','678 TEST SQL LOAD'
'LAURATEST1','188 HOME'
a5:/tmp 118 >
Enjoy, Have FUN! H.Merijn [ who would use DBI & DBD::Whatever ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 11:32 AM
11-29-2005 11:32 AM
Re: awk or perl to place 'around word'
# tr "\t" " "
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 11:33 AM
11-29-2005 11:33 AM
Re: awk or perl to place 'around word'
# tr "\t" " "
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 04:51 PM
11-29-2005 04:51 PM
Re: awk or perl to place 'around word'
# sed -e "s/\(^[^ ]*\) \(.*\)/'\1','\2'/" filename > tmp.file
# mv tmp.file filename
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 04:53 PM
11-29-2005 04:53 PM
Re: awk or perl to place 'around word'
# perl -pi -e "s/(^[^ ]*)(.*)/'\$1','\$2'/" filename
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 05:05 PM
11-29-2005 05:05 PM
Re: awk or perl to place 'around word'
# perl -pe "s/(^[^ ]*) (.*)/'\$1','\$2'/"
space needed.
AWK solution:
# awk -v tab="'" '{ printf tab$1tab","tab;for(i=2;i
# mv out
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2006 06:44 AM
01-18-2006 06:44 AM