I have a file with thousands of lines with fixed length fields:
sample (assume x is a blank space)
111333xx444TTTLKOPxxxxxxxxx
I need to make a copy of this file but with only some of the field positions, for example I'd like to copy the sample to the follwing: so I'd like to print bytes 4-5 and 15-16 and they be in the same character positions in the new file.
xxx33xxxxxxxxTLxxxxxxxxxxxxxxx
I started looking at cut -b4-5,15-16 but my output is in position 1-4 instead of the same 4-5 and 15-16 with blank spaces everywhere there was one in the original.
This does print the correct positions but does not fill in the spaces between with the same number of bytes turned to blanks that were in the original. For example, if we take the following 2 lines.
ABC123DEF
GEH456JKL
Say I want to print position 1-2 and 6-8 and want everything in between turned to blank spaces so the byte positions from my input are in the same positions as my output.
Say x is a blank space the output should look like:
ABxxx3DEx
GExxx6JKx
The suggested awk with substr gives me the right substrings but in the wrong position in the new file:
AB3DE
GE6JK
my samples are simplified so what I actually have are lines 300 bytes long.
I need to print bytes 1-3, 203-240, and 260-289, with blank spaces between so the output remains in the same position. This presents a problem with sed because putting 200 spaces in the replace segment doesn't make sense. The suggestions above are fine for my samples which are 10-12 bytes long but not for 300 byte long lines where are only need to print a few bytes across the line.
Interesting issue I have here I never thought would be so tricky to figure out when I started
Thanks everyone, this last post from Ygor looks like the easiest option. I've been playing with it this morning but getting a syntax error I can't get past.
awk: syntax error near line 2
awk: illegal statement near line 2
but my file in looks like
ABC SOLARIS 2200 MAIN STREET
My out file is getting 1's in place of the characters I want to print and 0's in place of the blank spaces I want:
1110000000000011111111100000111111111
I'm sure it's something simple but I'm not seeing it
You are correct, thanks Ygor! I was getting a syntax error as awk before so I altered it then changed it to nawk without replacing the changes i had made in awk. It does exactly what I need with a space in place of the "x".