![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| Break line after last "/" if length > X characters | SportBilly | Shell Programming and Scripting | 9 | 10-25-2008 03:15 PM |
| sed remove last 10 characters of a line start from 3rd line | minifish | Shell Programming and Scripting | 7 | 03-26-2008 04:42 PM |
| check position of end of line for some specific lines | senthil_is | Shell Programming and Scripting | 1 | 11-09-2007 01:19 AM |
| Deleting First Two Characters On Each Line | scotbuff | Shell Programming and Scripting | 5 | 12-16-2006 01:03 AM |
| Deleting the blank line in a file and counting the characters.... | rkumar28 | Shell Programming and Scripting | 4 | 04-17-2005 12:13 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I've got a file that would have lines similar to:
12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00 xx.00 I'm looking to basically do: if [ current line > 1208 characters ] delete characters at position 102-106 delete characters at position 1208-1214 copy modified line to new file else copy line as is to new file so the new file would be: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 all lines will start with an 8 digit key we don't know what the characters we are deleting will be (so no pattern searches) Right now I've been looking at doing a while read inputline loop and checking the character length of each line with the wc -m command. If -gt 1208 perform corrections and copy to new file. I wasn't sure if there was an easier way to do this -- and I haven't actually been able to figure out the best way to make the corrections to each individual line. Any ideas? Thanks! |
|
||||
|
I thought it had worked, but I must have had my line numbers mixed up when I checked it.
Right now I have this: Code:
awk '{if (length($0) <= 1280)
print
else
print substr($0, 1, 602) substr($0,610, 1208 -610) substr($0, 1214)
}' $oldFile > $newFile
I did a which gawk command and it says no gawk found ![]() I'm doing some more research myself to see if I can figure it out OS is Windows XP pro |
|
|||||
|
Windows XP, eh?
try putting the 'body' of the code code in a separate file - cailet.awk: cailet.awk: Code:
{
if (length($0) <= 1280)
print
else
print substr($0, 1, 602) substr($0,610, 1208 -610) substr($0, 1214)
}
Code:
awk -f cailet.awk $oldFile > $newFile |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|