- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to insert character/digit into txt file throug...
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
04-04-2007 06:08 AM
04-04-2007 06:08 AM
how to insert character/digit into txt file through sed/awk scripting
I need a help that how can i insert character/digit in line by line.
I want to add 3 numeric before 34th character, 3 character after 52, 1 character after 59th and 1 character after 75th.
How can i write a script by using awk/sed.
Thanks
Manish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2007 07:18 AM
04-04-2007 07:18 AM
Re: how to insert character/digit into txt file through sed/awk scripting
awk -f my.awk infile > outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2007 07:35 AM
04-04-2007 07:35 AM
Re: how to insert character/digit into txt file through sed/awk scripting
You can parse the input
- with substr as with awk as suggested earlier
- with a regular expression like:
/(.{33})(.{18}) ... /
- my favourite for this task: pack/unpack
($first,$second,...) = unpack "a33a18...
Good luck!
Hein van den Heuvel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2007 07:43 AM
04-04-2007 07:43 AM
Re: how to insert character/digit into txt file through sed/awk scripting
...and in addition Clay and Hein's suggestions to use 'substr' with either 'awk' or Perl or Perl's 'unpack()', you can write ugly 'sed' regular expression substitions like:
# echo "aaaaaa"|sed -ne 's/\(a\{3\}\)\(a\{3\}\)/X\1Y\2/p'
...which would produce:
XaaaYaaa
from: aaaaaa
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2007 08:10 AM
04-04-2007 08:10 AM
Re: how to insert character/digit into txt file through sed/awk scripting
# sed 's/^\(.\{33\}\)\(.\{19\}\)\(.\{7\}\)\(.\{16\}\)/\1987\2str\3c\4c/g' file
where 987 is an example of a 3-char length numeric to be added before the 34th character...so on and so forth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2007 08:22 AM
04-04-2007 08:22 AM
Re: how to insert character/digit into txt file through sed/awk scripting
Thanks for the prompt reply...
But i am not familier with awk/sed scripting, if you can provide me a script or sentence i would really appreciate.
Thanks
Manish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2007 08:23 AM
04-04-2007 08:23 AM
Re: how to insert character/digit into txt file through sed/awk scripting
Any numeric? Random pick?
Same numeric on all lines?
What would the value depend on?
For further help you may want to show us how far you got trying to solve this, and append a .txt file with a few (5?) sample lines which clearly show the data before and after the edit.
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2007 08:30 AM
04-04-2007 08:30 AM
Re: how to insert character/digit into txt file through sed/awk scripting
> But i am not familier with awk/sed scripting, if you can provide me a script or sentence i would really appreciate.
Well, the example both Sandman and I provided show one way to perform what you seek. You will need to modify the example to fit your character offsets and that which you want to inject.
Regular expressions syntax denotes any character with a dot ("."). The notation of:
.{33}
or escaped for 'sed':
.\{33\}
specifies any-character repeated 33-times.
The encapsulation of that into parenthesis:
\(.\{33\}\)
allows us to back-refrenece this as \1 . Each successive group of parenthesized elements is referenced as \2, \3, etc.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2007 08:30 AM
04-04-2007 08:30 AM
Re: how to insert character/digit into txt file through sed/awk scripting
I will give you one final hint:
{
s1=substr($0,1,33)
print s1,"999"
}
run that file through awk and see if a couple of ideas don't collide inside your head.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2007 05:24 AM
04-05-2007 05:24 AM
Re: how to insert character/digit into txt file through sed/awk scripting
As per guide by Stephenson, I am able to insert character/digit in file by awk command with substr function.
Thanks once again.
Manish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2007 05:26 AM
04-05-2007 05:26 AM