problem with awk command in script.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers problem with awk command in script.
# 1  
Old 09-02-2010
problem with awk command in script.

Code:
#!/bin/sh
date=`date +%y%m%d -d"1 day ago"`
inbound_dir=/vis/logfiles/to_solmis
            cp `grep -il ST~856~ $inbound_dir/*$date*` /vis/sumit/in_ASN/
            echo 'SENDER,RECEIVER,DATE,TIME,ASNUMBER' > a.csv
            for i in /vis/sumit/in_ASN/*
            do
                 mkdir -p /vis/sumit/inboundasns.$date
                 cp `echo $i` /vis/sumit/inboundasns.$date 
                 tr -c '[A-Z] [0-9] [a-z] ~' '[ *]' <$i > b
                 awk -F "DTM~" '{print $1}' b > c
                 awk -F "~SH~" '{print $2}' c > d
                 awk -F "~" '{print $1","$2","$3","$4","$11}' d >> a.csv
            done

Please suggest how to read or print a file which is of 3000 bytes using awk command..
Error is awk cannot read a file whose length is greater than 3000.
Any alternative ????

Last edited by Franklin52; 09-02-2010 at 03:14 AM.. Reason: Please use code tags!
# 2  
Old 09-02-2010
Quote:
Originally Posted by shrima.pratima
Please suggest how to read or print a file which is of 3000 bytes using awk command..
Error is awk cannot read a file whose length is greater than 3000
Are you sure?
try:
Code:
cat very_long_file.txt
awk very_long_file.txt

any errors, print it
What's your OS? What's version?
# 3  
Old 09-02-2010
Quote:
Originally Posted by john1212
Are you sure?
I believe he means lines, not files. Many versions do have an arbitrary limit on the length of lines.

If it's available on your system, try nawk instead of awk. That should be GNU awk, which doesn't have a limit that I'm aware of.
# 4  
Old 09-02-2010
Quote:
Originally Posted by john1212
Are you sure?
try:
Code:
cat very_long_file.txt
awk very_long_file.txt

any errors, print it
What's your OS? What's version?
Older awk's more than likely have such a limit. awk on Solaris, for example has a limit of 2.5K-1 byte line length.

Newer awk's most likely don't have such limitations.
# 5  
Old 09-03-2010
This is the difference.
There is no limit of file size.
There's a limit of record lenght.
Use nawk, gawk.
GNU awk is gawk. It's for many distributions.

Last edited by john1212; 09-03-2010 at 02:36 AM..
# 6  
Old 09-03-2010
nawk didnt work in my script.

Hi all,

Thanks for your reply.

I entered nawk instead of awk but didnt work.
error is: nawk not found.
My OS HP-UX.
my script is not able read the file and pick up the required fields when the total size of record was greater than 3000 bytes.

Error looks like:
awk: Input line ISA~00~ ~00 cannot be longer than 3,000 bytes.
The source line number is 1.

How to overcome this error??
# 7  
Old 09-03-2010
Is this a joke?
This is very funny.
Code:
tr -c '[A-Z] [0-9] [a-z] ~' '[ *]' <$i > b

you translate all characters A..Z, 0..9, a..z, ~ to ' ',
now you set FS-field separator to 'DTM~' (no any characters D, T, M, ~) what for
Code:
awk -F "DTM~" '{print $1}' b > c

.......
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

getting problem in awk command

Hi, I have one file with tab delimited values in it. i want to increase the value of 6th field by 2 if value of 3rd field is greater than 2 . The command is working fine but space between the field is getting removed after adding. below is the file and the command Filename: test1.txt ... (13 Replies)
Discussion started by: ravi_agarwalla
13 Replies

2. Shell Programming and Scripting

Problem with Variable and AWK command

Okay, so I am trying to use a count variable to reference the column of output sent from an echo statement. So I am trying to do this #!/bin/bash CURRENT=$PWD VAR=3 CHANGE=`echo $CURRENT | awk -F "/" '{ print \$$VAR }'` This instead of giving me the third instance after the "/" gives... (4 Replies)
Discussion started by: mkjp2011
4 Replies

3. Shell Programming and Scripting

Alias problem with awk command

Hi to all, I'm facing some problems when adding an alias like: #alias list="ls -al | awk '{ print $1, $2, $3, $4, (($5/1048576))"\t", $6, $7, $8, $9 }'" and when I enter: #list I get: Syntax Error The source line is 1. The error context is { print >>> , <<< awk:... (3 Replies)
Discussion started by: enux
3 Replies

4. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

5. Shell Programming and Scripting

problem with awk command

I have written some code in a KSH script to find the index of the character in a string like this #!usr/bin/ksh string="Hi How are you" awk 'BEGIN {print index ($string, "are")}' My expected output should be : 8 but it is giving the out put as : 0 I wanted to store that index value in... (8 Replies)
Discussion started by: hemanth424
8 Replies

6. Shell Programming and Scripting

problem with awk command

I am having problem running an awk commad on a file Before applying awk command on the file After applying I don't expect more than 409743 records in the file. Why do I have 1 record more after applying awk command? Please let me know (4 Replies)
Discussion started by: dsravan
4 Replies

7. Shell Programming and Scripting

Problem in awk command

Hello, I am getting problem in awk command during matching (using if in awk) when there is special character "" I have tried by loosing the special meaning, still its not working Below is my code: set pinname_watch = "DCORRECT" set pinname = "DCORRECT\" echo 'defineGateSize... (2 Replies)
Discussion started by: nehashine
2 Replies

8. Shell Programming and Scripting

Problem facing in using awk command

Hi., I am not able to replace the string with another string using gsub fn of awk command. My code: awk 'BEGIN gsub(004,IND,004)' p.txt and my i/p file p.txt is of the format: av|004|adkf|Kent,004|s av|005|ssdf|Kd,IT park|s . . . and my desired o/p should be of : (13 Replies)
Discussion started by: av_vinay
13 Replies

9. Post Here to Contact Site Administrators and Moderators

AWK command problem

How can I write an AWK so it could print some fixed strings and concatenate that with other words from an input file. Also having a string like "go" in the next line in the output file as below: Example: A fixed string like: "Hello my" and the input file is: friend mother father... (4 Replies)
Discussion started by: sybase08
4 Replies

10. Shell Programming and Scripting

problem in awk command

Hello all, i am new one to this forum. : i have file with these contents.. internal://project/squid-internal-static/icons/anthony-xpm.gif http://widget.blogrush.com/img/br.png http://www.wingware.com/css/print http://publib.boulder.ibm.com/infocenter/systems/advanced/filterwarning.css... (3 Replies)
Discussion started by: viveksnv
3 Replies
Login or Register to Ask a Question