- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed or awk on flat file with no separators swap da...
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
07-19-2006 07:55 AM
07-19-2006 07:55 AM
What I need to do is swap two data fields around.
Both are 38 characters, so I do not need to pad. (blank spaces)
I need to swap char 1-38 data field with char 87-124 data field for each line.
I loop will do, but will I need to store these in variables?
Appreciate the help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2006 08:06 AM
07-19-2006 08:06 AM
Re: sed or awk on flat file with no separators swap data on line
f1=`cat myfile | cut -c 1-38`
f2=`cat myfile | cut -c 39-86`
f3=`cat myfile | cut -c 87-124`
f4=`cat myfile | cut -c 125-`
echo ${f3}${f2}${f1}${f4} > mynewfile
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2006 08:19 AM
07-19-2006 08:19 AM
Re: sed or awk on flat file with no separators swap data on line
# perl -pe'@f=unpack"a38a48a3a*",$_;$_=join"",@f[2,1,0,3]' file
Many other options available. TMTOWTDI
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2006 08:21 AM
07-19-2006 08:21 AM
Re: sed or awk on flat file with no separators swap data on line
# perl -nle 'print $3.$2.$1.$4 if m/(.{38})(.{48})(.{38})(.{649})/' filename
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2006 08:22 AM
07-19-2006 08:22 AM
Re: sed or awk on flat file with no separators swap data on line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2006 08:28 AM
07-19-2006 08:28 AM
Re: sed or awk on flat file with no separators swap data on line
Thanks for the perl works great, how about only changing the lines that at the 206 & 207 char = XG?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2006 08:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2006 08:40 AM
07-19-2006 08:40 AM
Re: sed or awk on flat file with no separators swap data on line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2006 08:46 AM
07-19-2006 08:46 AM
Re: sed or awk on flat file with no separators swap data on line
Perhaps:
# perl -ne 'chomp;if (m/.{205}XG/ and m/(.{38})(.{48})(.{38})(.{649})/) {print $3.$2.$1.$4} else {print}' filename
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2006 10:23 AM
07-19-2006 10:23 AM
Re: sed or awk on flat file with no separators swap data on line
# perl -MBenchmark=:all -le'$a="a"x800;cmpthese(-2,{re=>q{$a=~m/(.{38})(.{48})(.{38})(.{649})/},pu=>q{unpack"a38a48a3a*",$a}})'
Rate re pu
re 263161/s -- -19%
pu 323570/s 23% --
worse for the .{238} thing, which is wrong anyway, as it ix not anchored. Please use substr there:
# perl -MBenchmark=:all -le'$a="aXG"x300;cmpthese(-2,{re=>q{$a=~m/^.{205}XG/},pu=>q{(unpack"x205a2",$a)[0]eq"XG"},ss=>q{substr($a,205,2)eq"XG"}})'
Rate re pu ss
re 782184/s -- -10% -66%
pu 868848/s 11% -- -63%
ss 2327702/s 198% 168% --
Regular expressions are powerful, and fun, but not the right tool for the given problem
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 08:19 AM
09-11-2006 08:19 AM
Re: sed or awk on flat file with no separators swap data on line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 01:43 PM
09-11-2006 01:43 PM
Re: sed or awk on flat file with no separators swap data on line
# perl -pe'if (substr($a,205,2)eq"XG") {@f=unpack"a38a48a3a*",$_;$_=join"",@f[2,1,0,3]}' file
>> flat file with no separators
seperators are overrated and a waste of space, cpu time, and flexibility.
The extra carriage return may have been an artifact of the subsequent transfer to OpenVMS
Please consider looking arounf for the right tools on OpenVMS to do the job 'in place'.
That field in position 205 may well have been an 'alternate key' and so you might have been able to jump straight to those target records withou reading any others... on OpenVMS.