- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Re: Can I truncate text file line to 100 character...
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-29-2007 11:41 PM
04-29-2007 11:41 PM
Can this be done with cat, awk or sed?
thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2007 11:53 PM
04-29-2007 11:53 PM
Re: Can I truncate text file line to 100 characters
CONVERT is the tool that does this the easiest.
Make an FDL file specifying record length 100, and
$ CONVERT/FDL=
and you are home.
For /PAD use either " " (one quoted space) of %X0 (binary zero)
Alternatively, if you want to retain the shorter records as-is, make a small DCL procedure:
$ open /read ifi
$ open /write ofi
$loop:
$ read ifi rec/end=done
$ write ofi f$extract(0,100,rec)
$ goto loop
$done:
$ close ifi
$ close ofi
hth
Prosst.
Have one on me
jpe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2007 12:51 AM
04-30-2007 12:51 AM
SolutionWelcome to the OpenVMS Forum.
Howerer, i think upi meant to post to a Unix forum.
Yes it can be done with awk or sed.
awk '{print substr($0,1,100)}' old > new
The most basic (fastes) tool to do this job on Unix is cut:
cut -c 1-100 old > new
Check the man pages for detail!
On OpenVMS I would use perl or convert
$CONV/TRUN/FDL="RECORD; SIZE 100" old new
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2007 05:13 AM
04-30-2007 05:13 AM
Re: Can I truncate text file line to 100 characters
$ perl -ne "print substr($_,0,100) . qq/\n/;" < foo.old > foo.new
Another would be to use the -i edit-in-place switch:
$ perl -n -i -e "print substr($_,0,100) . qq/\n/;" foo.dat
which will create a new version of foo.dat with all the lines truncated at 100.
Both of these methods will give you some extra newlines if some of the lines in the original file were less than 100 characters long. You can avoid that by trimming newlines first:
$ perl -n -i -e "$_ =~ s/\n\z//; print substr($_,0,100) . qq/\n/;" foo.tmp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2007 07:06 AM
04-30-2007 07:06 AM
Re: Can I truncate text file line to 100 characters
If You want to keep the text beond the clolumn 100, my TRIMCARD utility might be of use:
TRIMCARD
Syntax: TRIMCARD /COLUMN:n /WRAP /WORD file [default n=80]
TRIMCARD reads a (cardimage-) input-file and writes a
new output file with the same content, but
o all text beyond column /COLUMN:n [80] removed, and
o all trailing blanks removed.
Qualifier /WRAP: wrap line at column, do not cut.
Qualifier /WORD : wrap, but at word boundaries.
See http://wwwvms.mppmu.mpg.de/~huber/util/main/trimcard.html