Following one line of awk code removes first 3 characters from each line but when I run the same code on another linux platform it doesn't work and only prints blank lines for each record. Can anyone please explain why this doesn't work?
Please show the awk
versions of both platforms.
And, above doesn't do anything that
awk '{print substr($0,3)}' file1 > file2
wouldn't do.
Are you sure the input files are identical across platforms?
I don't understand what you mean by "above doesn't do anything that [code] wouldn't do". PLease explain.
awk version works: GNU Awk 3.1.3
awk version doesn't work: GNU Awk 3.1.7
Yes input files are identical
can you do cat -vet myInputFile
on both systems and post it here, pls.
[quote=later_troy;302970344]
I don't understand what you mean by "above doesn't do anything that
wouldn't do". PLease explain.
awk version works: GNU Awk 3.1.3
awk version doesn't work: GNU Awk 3.1.7
Yes input files are identical
The command:
awk 'NR==1{print substr($0,3);next}{print substr($0,3)}' file1 > file2
prints from the 3rd character to the end of the 1st input line in file1 and prints from the 3rd character to the end of the remaining lines from file1
into file2
, while the command:
awk '{print substr($0,3)}' file1 > file2
prints from the 3rd character to the end of every input line from file1
into file2
. In what way do you think the output produced by these two commands would be different?
Try out this awk command if you find it simpler...
awk -F"^..." '{print $2}' file
This doesn't work
awk -F"^..." '{print $2}' file > file2
It generates blank file2
Thanks for your explanation but we have tried this already and it doesn't work either. It still generates blank file2.
is that a good or a bad file?
Please post both files from both systems and tell us which one returns "blank lines".
There is no bad file, it's identical file on both system.
Can I see a file from the system that returns "blank lines", please.
The one I posted was from the system that return blank lines and trust me it's same file copied from the system where it works and your cat -vet command shows same first 3 junk characters in both systems.
Please post the output from the command:
head -n3 file1 | od -bc
run on the system where file2
ends up containing only blank lines after running the command:
awk '{print substr($0,3)}' file1 > file2
or the command:
awk -F'^...' '{print $2}' file1 > file2
And post both platforms' OS versions.
I suspect it's the ^C
that's causing issues.
Try this:
awk '{print substr($0,4)}' file1
Post a few lines from the output of cat -vet file
here as the input file seems to have non-printing characters which would throw off any well meaning code...
Here is the output of head command.
0000000 347 003 062 060 061 066 060 061 060 063 061 066 063 070 061 065
347 003 2 0 1 6 0 1 0 3 1 6 3 8 1 5
0000020 104 062 065 060 060 061 064 101 060 061 060 060 060 060 060 060
D 2 5 0 0 1 4 A 0 1 0 0 0 0 0 0
0000040 061 060 060 061 061 071 061 060 063 060 060 060 060 060 060 111
1 0 0 1 1 9 1 0 3 0 0 0 0 0 0 I
0000060 120 064 071 062 060 061 065 060 060 060 060 060 060 060 060 060
P 4 9 2 0 1 5 0 0 0 0 0 0 0 0 0
0000100 060 060 060 062 060 061 066 055 060 061 055 060 063 055 061 066
0 0 0 2 0 1 6 - 0 1 - 0 3 - 1 6
0000120 056 063 070 056 061 065 056 066 064 060 060 060 060 123 131 123
. 3 8 . 1 5 . 6 4 0 0 0 0 S Y S
0000140 124 120 122 120 117 062 060 061 066 055 060 061 055 060 063 055
T P R P O 2 0 1 6 - 0 1 - 0 3 -
0000160 061 066 056 063 070 056 061 065 056 066 064 060 060 060 060 040
1 6 . 3 8 . 1 5 . 6 4 0 0 0 0
0000200 040 040 040 040 040 040 040 040 040 040 040 040 040 040 040 040
*
0001740 040 040 040 040 040 040 040 040 040 012 347 003 062 060 061 066
\n 347 003 2 0 1 6
0001760 060 061 060 063 061 066 063 070 061 065 104 062 065 060 060 061
0 1 0 3 1 6 3 8 1 5 D 2 5 0 0 1
0002000 064 101 060 061 060 060 060 060 060 060 062 060 060 061 071 071
4 A 0 1 0 0 0 0 0 0 2 0 0 1 9 9
0002020 070 060 067 061 060 060 060 060 060 111 120 064 071 062 060 061
8 0 7 1 0 0 0 0 0 I P 4 9 2 0 1
0002040 065 060 060 060 060 060 060 060 060 060 060 060 060 062 060 061
5 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
0002060 066 055 060 061 055 060 063 055 061 066 056 063 070 056 061 065
6 - 0 1 - 0 3 - 1 6 . 3 8 . 1 5
0002100 056 066 064 060 060 060 060 123 131 123 124 120 122 120 117 062
. 6 4 0 0 0 0 S Y S T P R P O 2
0002120 060 061 066 055 060 061 055 060 063 055 061 066 056 063 070 056
0 1 6 - 0 1 - 0 3 - 1 6 . 3 8 .
0002140 061 065 056 066 064 060 060 060 060 040 040 040 040 040 040 040
1 5 . 6 4 0 0 0 0
0002160 040 040 040 040 040 040 040 040 040 040 040 040 040 040 040 040
*
0003720 040 040 040 012 347 003 062 060 061 066 060 061 060 063 061 066
\n 347 003 2 0 1 6 0 1 0 3 1 6
0003740 063 070 061 065 104 062 065 063 060 061 064 101 060 062 060 060
3 8 1 5 D 2 5 3 0 1 4 A 0 2 0 0
0003760 060 060 060 060 062 060 060 060 060 060 060 060 060 060 060 062
0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2
0004000 060 066 061 066 062 060 061 065 065 061 060 060 060 060 060 060
0 6 1 6 2 0 1 5 5 1 0 0 0 0 0 0
0004020 067 061 060 065 060 040 060 060 060 060 060 060 061 060 060 060
7 1 0 5 0 0 0 0 0 0 0 1 0 0 0
0004040 060 060 060 061 060 060 060 060 060 060 060 060 060 060 060 060
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0004060 060 060 060 060 062 061 131 131 103 117 127 040 070 061 065 062
0 0 0 0 2 1 Y Y C O W 8 1 5 2
0004100 065 063 103 040 040 040 040 040 040 040 040 040 040 040 040 040
5 3 C
0004120 116 040 060 040 040 040 040 040 062 060 061 066 055 060 061 055
N 0 2 0 1 6 - 0 1 -
0004140 060 063 055 061 066 056 063 070 056 061 065 056 066 064 060 060
0 3 - 1 6 . 3 8 . 1 5 . 6 4 0 0
0004160 060 060 123 131 123 124 120 122 120 117 062 060 061 066 055 060
0 0 S Y S T P R P O 2 0 1 6 - 0
0004200 061 055 060 063 055 061 066 056 063 070 056 061 065 056 066 064
1 - 0 3 - 1 6 . 3 8 . 1 5 . 6 4
0004220 060 060 060 060 040 040 040 040 040 040 040 040 060 060 060 060
0 0 0 0 0 0 0 0
0004240 060 060 060 060 040 040 040 040 040 040 040 040 040 040 040 040
0 0 0 0
0004260 040 040 040 040 040 040 040 040 040 040 040 040 040 040 040 040
*
0005660 040 040 040 040 040 040 040 040 040 040 040 040 040 012
\n
0005676
None of the following works it print blank lines
awk '{print substr($0,3)}' file1 > file2
or
awk -F'^...' '{print $2}' file1 > file2
or
awk '{print substr($0,4)}' file1
Version of both platforms
Not Working version: Red Hat Enterprise Linux Server release 6.5 (Santiago)
2.6.32-504.el6.x86_64
Working Version: Red Hat Enterprise Linux ES release 4 (Nahant Update 5)
2.6.9-103.ELsmp
Can you post the output of "cat -vet file" on the first 3 or 4 lines of the input file here...