Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a question

Status
Not open for further replies.

vti

Technical User
Feb 26, 2001
189
TR
i have a file like ;

H99200020020313 T0000003000001322647000
H99207020020313
T0000017000000581060000
..
follows at same format with diferent data.
And i'd like to cut some data until end of file and create an output to a file like ;

2000 0000003 000001322647000
2070 0000017 000000581060000


'2000' is 3-7 characters of first line .
'0000003' is 1-8 characters of second line
'000001322647000' is 9-24 characters of second line.


Thanks for any help.

 
Something doesn't compute beteen the data you gave and the character positions you specified but something like this may work.
Code:
printf substr($0,3,5) " "
getline
print substr($0,1,8) " " substr($0,9,16)
Note that character positions in the substr command are one relative not zero relative.

Hope this helps.
CaKiwi
 
Hi CaKiwi thanks for reply, i think data which i gave as example moved to right a bit when i submit the question.The true one i will give below.

H99200020020313
T0000003000001322647000
H99207020020313
T0000017000000581060000

I want to cut 4 characters(2000) after "H99" from first line
and cut 7 characters(0000003) after "T" of second line and also want to cut the last 15 characters of second line .

I have tried your way but couldn't run it.Would you tell me the right way to run it.

Thanks
 
One way to run it is to put this script into a file, a.awk say,
Code:
{
  printf substr($0,4,4) " "
  getline
  print substr($0,2,7) " " substr($0,9)
}
and enter awk -f a.awk your-file

Hope this helps. CaKiwi
 
it works well
Thanks a lot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top