![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| aside from paste | kenshinhimura | Shell Programming and Scripting | 3 | 03-11-2008 01:16 AM |
| paste several files | tonet | Shell Programming and Scripting | 1 | 10-05-2007 11:08 AM |
| cut & paste | t_harsha18 | Shell Programming and Scripting | 3 | 10-02-2005 04:16 AM |
| paste command | mariner | UNIX for Advanced & Expert Users | 5 | 03-04-2005 02:42 AM |
| awk or sed or paste | leprichaun | UNIX for Dummies Questions & Answers | 3 | 11-16-2003 07:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Cut Paste and Insert Help
Hello
I have a very large file where say each line is made up of 80 characters. I want to cut the characters from 20-30 and 50-60 from each line and then insert a delimiter between them (# or | etc). eg input file 000000000131.12.20990000590425246363375670011200140406 000000000131.12.20990000599116259067695570011200140306 000000000131.12.20990000954757586517205670011200140206 000000000131.12.20990001100136286779157070040749470106 000000000131.12.20990001100331729172935570040774630106 000000000131.12.20990001100417542814864770040736610106 000000000131.12.20990001100565052159608570040771070106 output file 209900005#700112001404 209900005#700112001403 209900009#700112001402 209900011#700407494701 209900011#700407746301 209900011#700407366101 209900011#700407710701 I can cut the relevant characters and put them in 2 files and then using cut paste option make a new file with the desired results. However this will take a long time as the file is huge. Is there a simpler way. Please help. Thanks in advance Regards Pradeep |
|
||||
|
first cut the relavent columns and then store in a temp files, then use the paste command to insert the delimiter then at last remove the temp files.
cut -c 20-30 data > t1 ; cut -c 50-54 data > t2 ; paste -d "#" t? ; rm t? |
|
|||||
|
If it is always 20-30 and 50-60, you can use the bash builtin to do what cut does. Something like Code:
LHS=${line:20:10}
RHS=$(line:50:10}
OUTPUT="${LHS}#${RHS}"
See this post See man sh for further info. |
|
||||
|
I request you to pls elaborate on the code given. If my data is present in a file named a1, then how do i use your code to get a file a2 with the desired output. I could not figure out how to use the variables LHS and RHS to extract data from a line in a file.
Regards |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|