KSH: A PROBLEM awk SUBSTRING


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH: A PROBLEM awk SUBSTRING
# 1  
Old 02-03-2011
KSH: A PROBLEM awk SUBSTRING

Hi Gurus,
I am working with a korn shell script to simplify some operations of creation file of spool for a Bulk-Copy. Thi is my code:


In a for cycle:

Code:
gzcat ${file} |awk '{ print substr($0,1,5)";"substr($0,108,122)";"substr($0,124,131)";"substr($0,139,152)";"substr($0,154,163)";"}' >> FileBcp.bcp

but in output I don't get only the interested columns, but the more columns the whole line...

This is what I would want:

Code:
43031;20110128080700;ALBAM01;0;20110128080700;001234567;

questo è quello che ottengo:

Code:
 43031;20110128080700;ALBAM01;0;20110128080700;001234567;012535007124830                  *TAP3V1*03314             *393291408157   *033;            ;         ;00           ;012535007124830                  *TAP3V1*03314             *393291408157   *03314*            *     1111          +;       ;00           ;012535007124830                  *TAP3V1*03314             *393291408157   *03314*            *     1111          +010032          355680200*;


where is the error?



I would want to bring on an only file
# 2  
Old 02-03-2011
try switching the print statement to a printf statement:
Code:
gzcat ${file} |awk '{
  printf("%s;%s;%s;%s;%s;%s;\n",substr($0,1,5),substr($0,108,122),substr($0,124,
131),substr($0,139,152),substr($0,154,163))
}' >> FileBcp.bcp

# 3  
Old 02-03-2011
good idea, but I get this error:

Code:
 
gzcat: compressed data not read from a terminal. Use -f to force decompression.

# 4  
Old 02-03-2011
gzcat cats a gzipped file it does not compress.
The gzcat utility behaves just like the gunzip -c command. (On some systems, gzcat is installed as zcat
# 5  
Old 02-03-2011
Hi,
the command works, but the result is not correct. In output it always brings the whole line....
# 6  
Old 02-03-2011
So your script worked with the gzcat but just gave bad output. But now it gives a gzcat error?
hmmm all I did was change from print to printf in the awk should not have affected the gzcat.

I guess I may need more view of the script. and a small sample of the file.
# 7  
Old 02-03-2011
all ok I mistook me...!!!!

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substring Problem with sed . . .

Greetings. I'm looking to isolate the first occurrence of an arbitrary substring which may be present at any particular line in a given file. The enclosing end markers for the target in our thought problem are string" and ". The complete string and surrounding text could look something like... (3 Replies)
Discussion started by: LinQ
3 Replies

2. UNIX for Dummies Questions & Answers

Substring AIX ksh

I am trying to obtain a substring in AIX, but unable to obtain result ${var:1:3} ksh: ${var:1:3}: bad substitution (3 Replies)
Discussion started by: tostay2003
3 Replies

3. UNIX for Advanced & Expert Users

awk if/substring/append help

Hi All, I need some help with an awk command: What I'm trying to do is append "MYGROUP: " to text with the substring "AT_" the input file follows this format: AT_xxxxxx Name1 Name2 AT_xxxxxx NameA NameB I want the output to be: MYGROUP: AT_xxxxx Name1 Name2 MYGROUP:... (2 Replies)
Discussion started by: bikecraft
2 Replies

4. Shell Programming and Scripting

AWK: Substring search

Hi I have a table like this I want to know how many times the string in 2nd column appears in the first column as substring. For example the first string of 2nd column "cgt" occurs 3 times in the 1st column and "acg" one time. So my desired output is THank you very much in advance:) (14 Replies)
Discussion started by: polsum
14 Replies

5. Shell Programming and Scripting

Getting substring with awk

Hi Team, How to get the last 3 characters of a String irrespective of their length using awk? Thanks Kinny (5 Replies)
Discussion started by: kinny
5 Replies

6. Shell Programming and Scripting

Problem with Substring

Hi, i have a file from which i extracted 2nd column and put it into a variable Acct_Num . Now i need to extract first 3 digits from it and save in to other variable. My Code is: while read Record1 do Acct_Num=`echo $Record1 | awk '{print $2 }'` ID=`echo $Record1 | awk '{print... (3 Replies)
Discussion started by: manmeet
3 Replies

7. Shell Programming and Scripting

Substring problem

I have a file which comes with a few tags and some contents inside them. eg: <ABC>Hello Unix.com</ABC> <XYZ>WWSHF</XYZ> Now I want to pick out the contents in between the tags <ABC> and </ABC>. The contents within <ABC> and </ABC> spans more than one line. So greping and cutting is not an... (4 Replies)
Discussion started by: Rajat
4 Replies

8. UNIX for Dummies Questions & Answers

problem extracting substring in korn shell

hi all, I have read similiar topics in this board, but i didn' t find the posting which is the same with the problem i face.. I try to extract string from the end. i try to do this: num=abcdefghij num2=${num:-5} echo $num2 #this should print the last 5 characters (fghij) but it doesn;t... (3 Replies)
Discussion started by: nashrul
3 Replies

9. UNIX for Dummies Questions & Answers

substring using AWK

can we do substring fuctionality using AWK say I have string "sandeep" can i pick up only portion "nde" from it. Thanks and Regards Sandeep Ranade (3 Replies)
Discussion started by: mahabunta
3 Replies

10. UNIX for Dummies Questions & Answers

ksh substring commands

I am trying to get various portions of strings in my script, but am getting a substitution error. I followed the syntax that was described when I goggled this, but I can't get anything to work. #! /bin/ksh/ hello="adklafk;afak" #hello=${hello:3} hello=${$hello:3} happy="hey" echo... (1 Reply)
Discussion started by: anderssl
1 Replies
Login or Register to Ask a Question