awk command not working as expected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command not working as expected
# 15  
Old 04-06-2016
Please post the output from the command:
Code:
head -n3 file1 | od -bc

run on the system where file2 ends up containing only blank lines after running the command:
Code:
awk '{print substr($0,3)}' file1 > file2

or the command:
Code:
awk -F'^...' '{print $2}' file1 > file2

# 16  
Old 04-06-2016
And post both platforms' OS versions.
# 17  
Old 04-06-2016
I suspect it's the ^C that's causing issues.
Try this:
Code:
awk '{print substr($0,4)}' file1

# 18  
Old 04-06-2016
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...
# 19  
Old 04-06-2016
Quote:
Originally Posted by Don Cragun
Please post the output from the command:
Code:
head -n3 file1 | od -bc

run on the system where file2 ends up containing only blank lines after running the command:
Code:
awk '{print substr($0,3)}' file1 > file2

or the command:
Code:
awk -F'^...' '{print $2}' file1 > file2

Here is the output of head command.

Code:
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
Code:
 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
# 20  
Old 04-06-2016
Can you post the output of "cat -vet file" on the first 3 or 4 lines of the input file here...
# 21  
Old 04-06-2016
Quote:
Originally Posted by shamrock
Can you post the output of "cat -vet file" on the first 3 or 4 lines of the input file here...
I already did that before see previous replies.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk matching script not working as expected

This is my ubuntu version: $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.4 LTS Release: 16.04 Codename: xenial $ /bin/awk -V | head -n1 bash: /bin/awk: No such file or directory I have gotten a script that helps me to parse,... (14 Replies)
Discussion started by: delbroooks
14 Replies

2. Shell Programming and Scripting

awk gsub not working as expected

Hi Experts, Need your kind help with gsub awk. Below is my pattern:"exec=1_host_cnt=100_dup=4_NameTag=targetSrv_500.csv","'20171122112948"," 100"," 1"," 1"," 4","400","","", " aac sample exec ""hostname=XXXXX commandline='timeout 10 openssl speed -multi 2 ; exit 0'"" ","-1","-1","1","... (6 Replies)
Discussion started by: pradyumnajpn10
6 Replies

3. Shell Programming and Scripting

Cp command not working as expected in HPUX

Hi, I'm having trouble with a simple copy command in a script on HPUX. I am trying to copy a file and append date & time. The echo command prints out what I am expecting.. echo "Backing up $file to $file.$DATE.$FIXNUM" | tee -a $LOGFILE + echo 'Backing up... (4 Replies)
Discussion started by: Glennyp
4 Replies

4. Shell Programming and Scripting

awk not working as expected in script

Dear all, I had script which used to work, but recently it is not working as expected. I have command line in my shell script to choose the following format from the output_elog and perform some task afterwards on As you see, I want all numbers in foramt following RED mark except for... (12 Replies)
Discussion started by: emily
12 Replies

5. Shell Programming and Scripting

Read command not working as expected

I was trying to write a simple script which will read a text file and count the number of vowels in the file. My code is given below - #!/bin/bash file=$1 v=0 if then echo "$0 filename" exit 1 fi if then echo "$file not a file" exit 2 fi while read -n... (14 Replies)
Discussion started by: linux_learner
14 Replies

6. Shell Programming and Scripting

bash variable (set via awk+sed) not working as expected

Hi! Been working on a script and I've been having a problem. I've finally narrowed it down to this variable I'm setting: servername=$(awk -v FS=\/ '{ print $7 } blah.txt | sed 's\/./-/g' | awk -v FS=\- '{print $1}')" This will essentially pare down a line like this: ... (7 Replies)
Discussion started by: creativedynamo
7 Replies

7. OS X (Apple)

Cat command not working as expected

I've been trying to figure this out since last night, and I'm just stumped. The last time I did any shell scripting was 8 years ago on a Unix box, and it was never my strong suit. I'm on a Mac running Leopard now. Here's my dilemma - hopefully someone can point me in the right direction. I'm... (10 Replies)
Discussion started by: Daniel M. Clark
10 Replies

8. UNIX for Dummies Questions & Answers

Find command not working as expected

I have a script with a find command using xargs to copy the files found to another directory. The find command is finding the appropriate file, but it's not copying. I've checked permissions, and those are all O.K., so I'm not sure what I'm missing. Any help is greatly appreciated. This is... (2 Replies)
Discussion started by: mpflug
2 Replies

9. Shell Programming and Scripting

Var substitution in awk - not working as expected

countA=`awk '/X/''{print substr($0,38,1)}' fName | wc -l` countB=`wc -l fName | awk '{print int($1)}'` echo > temp ratio=`awk -va=$countA -vc=$countB '{printf "%.4f", a/c}' temp` After running script for above I am getting an error as : awk: 0602-533 Cannot find or open file -vc=25. The... (3 Replies)
Discussion started by: videsh77
3 Replies

10. Shell Programming and Scripting

awk not working as expected with BIG files ...

I am facing some strange problem. I know, there is only one record in a file 'test.txt' which starts with 'X' I ensure that with following command, awk /^X/ test.txt | wc -l This gives me output = '1'. Now I take out this record out of the file, as follows : awk /^X/ test.txt >... (1 Reply)
Discussion started by: videsh77
1 Replies
Login or Register to Ask a Question